#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 */
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int create_server(int);
int /*<<< orphan*/ handle_route_request(int);
int /*<<< orphan*/ perror(char *);
void *route_handler(void *t) {
  int listenfd, connfd;
  if ((listenfd = create_server(2003)) < 0) {
    perror("could not create server : ");
    return NULL;
  }
  for (;;) {
    if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) < 0) {
      perror("accept error : ");
      return NULL;
    }
    handle_route_request(connfd);
    close(connfd);
  }
}


x86 assembly (clang, -O0):
<route_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x7d3,%edi
call   1030 <create_server@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    118b <route_handler+0x3b>
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <route_handler+0x89>
jmp    1190 <route_handler+0x40>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1070 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11c4 <route_handler+0x74>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <route_handler+0x89>
mov    -0x18(%rbp),%edi
call   1050 <handle_route_request@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    1190 <route_handler+0x40>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<route_handler>:
push   %rbp
push   %r14
push   %rbx
mov    $0x7d3,%edi
call   1030 <create_server@plt>
test   %eax,%eax
jns    116b <route_handler+0x1b>
lea    0xe97(%rip),%r14
jmp    11af <route_handler+0x5f>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <accept@plt>
lea    0xe9c(%rip),%r14
test   %eax,%eax
js     11af <route_handler+0x5f>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1050 <handle_route_request@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1190 <route_handler+0x40>
mov    %r14,%rdi
call   1060 <perror@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"could not create server : \00"
@.str.1 = [16 x i8] c"accept error : \00"
define i8* @route_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @create_server(i32 2003)
store i32 %6, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %22
10: ; preds = %1
br label %11
11: ; preds = %17, %10
%12 = load i32, i32* %4
%13 = call i32 @accept(i32 %12, %struct.sockaddr* null, i32* null)
store i32 %13, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %22
17: ; preds = %11
%18 = load i32, i32* %5
%19 = call i32 @handle_route_request(i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
br label %11
22: ; preds = %15, %8
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"could not create server : \00"
@.str.1 = [16 x i8] c"accept error : \00"
define noalias i8* @route_handler(i8* nocapture readnone %0) {
%2 = tail call i32 @create_server(i32 2003)
%3 = icmp slt i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 @accept(i32 %2, %struct.sockaddr* null, i32* null)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4, %7
%8 = phi i32 [ %11, %7 ], [ %5, %4 ]
%9 = tail call i32 @handle_route_request(i32 %8)
%10 = tail call i32 @close(i32 %8)
%11 = tail call i32 @accept(i32 %2, %struct.sockaddr* null, i32* null)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %7, %4, %1
%14 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %7 ]
%15 = tail call i32 @perror(i8* %14)
ret i8* null
}