#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*/ value;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int MakeServer(int backlog) {
  int ret;
  int sockfd = socket(PF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    do {
      perror("create socket");
      exit(EXIT_FAILURE);
    } while (0);
  struct sockaddr_in addr;
  addr.sin_port = htons(80);
  addr.sin_family = AF_INET;
  if ((ret = inet_pton(PF_INET, "0.0.0.0", &(addr.sin_addr))) < 0)
    do {
      perror("convert to ip");
      exit(EXIT_FAILURE);
    } while (0);
  int value = 1;
  if ((ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &value,
                        sizeof(value))) < 0)
    do {
      perror("set socket");
      exit(EXIT_FAILURE);
    } while (0);
  if ((ret = bind(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr))) <
      0)
    do {
      perror("bind socket");
      exit(EXIT_FAILURE);
    } while (0);
  if ((ret = listen(sockfd, backlog)) < 0)
    do {
      perror("listen socket");
      exit(EXIT_FAILURE);
    } while (0);
  return sockfd;
}


x86 assembly (clang, -O0):
<MakeServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11d0 <MakeServer+0x50>
jmp    11b6 <MakeServer+0x36>
lea    0xe43(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xe11(%rip),%rsi
call   1050 <inet_pton@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    122d <MakeServer+0xad>
jmp    1213 <MakeServer+0x93>
lea    0xdfc(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1283 <MakeServer+0x103>
jmp    1269 <MakeServer+0xe9>
lea    0xdb4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1070 <bind@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    12bf <MakeServer+0x13f>
jmp    12a5 <MakeServer+0x125>
lea    0xd83(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1060 <listen@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    12f5 <MakeServer+0x175>
jmp    12db <MakeServer+0x15b>
lea    0xd59(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeServer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
mov    0x2e36(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     123e <MakeServer+0xbe>
mov    %eax,%ebp
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
lea    0xe3c(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1050 <inet_pton@plt>
test   %eax,%eax
js     1247 <MakeServer+0xc7>
movl   $0x1,0xc(%rsp)
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1250 <MakeServer+0xd0>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1070 <bind@plt>
test   %eax,%eax
js     1259 <MakeServer+0xd9>
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <listen@plt>
test   %eax,%eax
js     1262 <MakeServer+0xe2>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdbb(%rip),%rdi
jmp    1269 <MakeServer+0xe9>
lea    0xdc8(%rip),%rdi
jmp    1269 <MakeServer+0xe9>
lea    0xdcd(%rip),%rdi
jmp    1269 <MakeServer+0xe9>
lea    0xdcf(%rip),%rdi
jmp    1269 <MakeServer+0xe9>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"create socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [14 x i8] c"convert to ip\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [11 x i8] c"set socket\00"
@.str.4 = [12 x i8] c"bind socket\00"
@.str.5 = [14 x i8] c"listen socket\00"
define i32 @MakeServer(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %1
%19 = call i32 @htons(i32 80)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @PF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%25 = call i32 @inet_pton(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %24)
store i32 %25, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %18
br label %28
28: ; preds = %27
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; No predecessors!
br label %33
33: ; preds = %32, %18
store i32 1, i32* %6
%34 = load i32, i32* %4
%35 = load i32, i32* @SOL_SOCKET
%36 = load i32, i32* @SO_REUSEADDR
%37 = call i32 @setsockopt(i32 %34, i32 %35, i32 %36, i32* %6, i32 4)
store i32 %37, i32* %3
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
br label %40
40: ; preds = %39
%41 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; No predecessors!
br label %45
45: ; preds = %44, %33
%46 = load i32, i32* %4
%47 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%48 = call i32 @bind(i32 %46, %struct.sockaddr* %47, i32 4)
store i32 %48, i32* %3
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %45
br label %51
51: ; preds = %50
%52 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %45
%57 = load i32, i32* %4
%58 = load i32, i32* %2
%59 = call i32 @listen(i32 %57, i32 %58)
store i32 %59, i32* %3
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %56
br label %62
62: ; preds = %61
%63 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; No predecessors!
br label %67
67: ; preds = %66, %56
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"create socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [14 x i8] c"convert to ip\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [11 x i8] c"set socket\00"
@.str.4 = [12 x i8] c"bind socket\00"
@.str.5 = [14 x i8] c"listen socket\00"
define i32 @MakeServer(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = bitcast %struct.sockaddr_in* %2 to i8*
%14 = tail call i32 @htons(i32 80)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @PF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%20 = call i32 @inet_pton(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %12
%27 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i32 @setsockopt(i32 %6, i32 %28, i32 %29, i32* %3, i32 4)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
%37 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%38 = call i32 @bind(i32 %6, %struct.sockaddr* %37, i32 4)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = call i32 @listen(i32 %6, i32 %0)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %44
ret i32 %6
}