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

/* Variables and functions */
int create_server_proc(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ handle_client_proc(int);
scalar_t__ server_init();
int /*<<< orphan*/ server_uninit();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int srvfd;
  if (server_init() < 0) {
    return -1;
  }
  srvfd = create_server_proc("127.0.0.1", 8787);
  if (srvfd < 0) {
    fprintf(stderr, "socket create or bind fail.\n");
    goto err;
  }
  handle_client_proc(srvfd);
  return 0;
err:
  server_uninit();
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <server_init@plt>
cmp    $0x0,%rax
jge    1183 <main+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <main+0x8d>
lea    0xe76(%rip),%rdi
mov    $0x2253,%esi
call   1070 <create_server_proc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bb <main+0x6b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11cf <main+0x7f>
mov    -0x14(%rbp),%edi
call   1030 <handle_client_proc@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dd <main+0x8d>
mov    $0x0,%al
call   1040 <server_uninit@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <server_init@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     119e <main+0x4e>
lea    0xe97(%rip),%rdi
mov    $0x2253,%esi
call   1070 <create_server_proc@plt>
test   %eax,%eax
js     1182 <main+0x32>
mov    %eax,%edi
call   1030 <handle_client_proc@plt>
xor    %ebx,%ebx
jmp    119e <main+0x4e>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <server_uninit@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"socket create or bind fail.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @server_init()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %22
10: ; preds = %2
%11 = call i32 @create_server_proc(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8787)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = load i32, i32* %6
%19 = call i32 @handle_client_proc(i32 %18)
store i32 0, i32* %3
br label %22
20: ; preds = %14
%21 = call i32 (...) @server_uninit()
store i32 -1, i32* %3
br label %22
22: ; preds = %20, %17, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"socket create or bind fail.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @server_init()
%4 = icmp slt i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @create_server_proc(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8787)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (...) @server_uninit()
br label %14
12: ; preds = %5
%13 = tail call i32 @handle_client_proc(i32 %6)
br label %14
14: ; preds = %2, %8, %12
%15 = phi i32 [ -1, %8 ], [ 0, %12 ], [ -1, %2 ]
ret i32 %15
}