#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
char *getLastRequest(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ respond(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void request_handler(int n) {
  char response[255], *lastRequest;
  printf("client request arrived\n");
  pid_t lastClient;
  lastRequest = getLastRequest(&lastClient);
  printf("%s\n", lastRequest);
  sprintf(response, "chau %s", lastRequest);
  respond(response, lastClient);
}


x86 assembly (clang, -O0):
<request_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x11c(%rbp),%rdi
call   1050 <getLastRequest@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x11c(%rbp),%esi
call   1030 <respond@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_handler>:
push   %r14
push   %rbx
sub    $0x118,%rsp
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
call   1050 <getLastRequest@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0xe8e(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1030 <respond@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"client request arrived\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"chau %s\00"
define void @request_handler(i32 %0) {
%2 = alloca i32
%3 = alloca [255 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @getLastRequest(i32* %5)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %5
%15 = call i32 @respond(i8* %13, i32 %14)
ret void
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"chau %s\00"
@str = [23 x i8] c"client request arrived\00"
define void @request_handler(i32 %0) {
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = bitcast i32* %3 to i8*
%7 = call i8* @getLastRequest(i32* %3)
%8 = call i32 @puts(i8* dereferenceable(1) %7)
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%10 = load i32, i32* %3
%11 = call i32 @respond(i8* %4, i32 %10)
ret void
}