#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process_rq(char *, int);
int /*<<< orphan*/ read_til_crnl(int /*<<< orphan*/ *);
void *handle_call(void *arg) {
  FILE *fpin;
  char request[1024];
  int fd;
  fd = *(int *)arg;
  free(arg);
  fpin = fdopen(fd, "r");
  fgets(request, 1024, fpin);
  printf("got a call: request = %s", request);
  read_til_crnl(fpin);
  process_rq(request, fd);
  fclose(fpin);
}


x86 assembly (clang, -O0):
<handle_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x424(%rbp),%edi
lea    0xe5f(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x420(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_til_crnl@plt>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
call   1060 <process_rq@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_call>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    (%rdi),%ebp
call   1030 <free@plt>
lea    0xe77(%rip),%rsi
mov    %ebp,%edi
call   1090 <fdopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
lea    0xe55(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <read_til_crnl@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <process_rq@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"got a call: request = %s\00"
define i8* @handle_call(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = load i8*, i8** %3
%11 = call i32 @free(i8* %10)
%12 = load i32, i32* %6
%13 = call i32* @fdopen(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32 @fgets(i8* %14, i32 1024, i32* %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %4
%20 = call i32 @read_til_crnl(i32* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i32 @process_rq(i8* %21, i32 %22)
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"got a call: request = %s\00"
define noalias i8* @handle_call(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = tail call i32 @free(i8* %0)
%7 = tail call i32* @fdopen(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @fgets(i8* %3, i32 1024, i32* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = call i32 @read_til_crnl(i32* %7)
%11 = call i32 @process_rq(i8* %3, i32 %5)
%12 = call i32 @fclose(i32* %7)
ret i8* undef
}