#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 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);
  }
}


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    117b <route_handler+0x3b>
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c1 <route_handler+0x81>
jmp    1180 <route_handler+0x40>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1060 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11b4 <route_handler+0x74>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c1 <route_handler+0x81>
mov    -0x18(%rbp),%edi
call   1040 <handle_route_request@plt>
jmp    1180 <route_handler+0x40>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<route_handler>:
push   %r14
push   %rbx
push   %rax
mov    $0x7d3,%edi
call   1030 <create_server@plt>
test   %eax,%eax
jns    116b <route_handler+0x2b>
lea    0xea7(%rip),%r14
mov    %r14,%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <accept@plt>
lea    0xe9c(%rip),%r14
test   %eax,%eax
js     1159 <route_handler+0x19>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1040 <handle_route_request@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <accept@plt>
test   %eax,%eax
jns    1190 <route_handler+0x50>
jmp    1159 <route_handler+0x19>

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 %20
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 %20
17: ; preds = %11
%18 = load i32, i32* %5
%19 = call i32 @handle_route_request(i32 %18)
br label %11
20: ; preds = %15, %8
%21 = load i8*, i8** %2
ret i8* %21
}

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 %12, 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 %12, label %7
7: ; preds = %4, %7
%8 = phi i32 [ %10, %7 ], [ %5, %4 ]
%9 = tail call i32 @handle_route_request(i32 %8)
%10 = tail call i32 @accept(i32 %2, %struct.sockaddr* null, i32* null)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7, %4, %1
%13 = 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 ]
%14 = tail call i32 @perror(i8* %13)
ret i8* null
}