#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 BUFSIZ;
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 *, int, char *);
int /*<<< orphan*/ process_rq(char *, int);
int /*<<< orphan*/ skip_rest_of_header(int /*<<< orphan*/ *);
void *handle_call(void *fdptr) {
  FILE *fpin;
  char request[BUFSIZ];
  int fd;
  fd = *(int *)fdptr;
  free(fdptr);
  fpin = fdopen(fd, "r");
  fgets(request, BUFSIZ, fpin);
  printf("got a call on %d: request = %s", fd, request);
  skip_rest_of_header(fpin);
  process_rq(request, fd);
  fclose(fpin);
  return 0;
}


x86 assembly (clang, -O0):
<handle_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
lea    0xe3c(%rip),%rsi
call   1090 <fdopen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1070 <fgets@plt>
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%esi
lea    0xe11(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <skip_rest_of_header@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <process_rq@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_call>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e5e(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rdi),%r14d
call   1030 <free@plt>
lea    0xe5a(%rip),%rsi
mov    %r14d,%edi
call   1090 <fdopen@plt>
mov    %rax,%r15
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <fgets@plt>
lea    0xe3b(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1060 <printf@plt>
mov    %r15,%rdi
call   1080 <skip_rest_of_header@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <process_rq@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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