#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int listenfd;
  if ((listenfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
    do {
      perror("socket");
      exit(EXIT_FAILURE);
    } while (0);
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5188);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  int on = 1;
  if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
    do {
      perror("setsockopt");
      exit(EXIT_FAILURE);
    } while (0);
  if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    do {
      perror("bind");
      exit(EXIT_FAILURE);
    } while (0);
  if (listen(listenfd, SOMAXCONN) < 0)
    do {
      perror("listen");
      exit(EXIT_FAILURE);
    } while (0);
  struct sockaddr_in peeraddr;
  socklen_t peerlen;
  int conn;
  if ((conn = accept(listenfd, (struct sockaddr *)&peeraddr, &peerlen)) < 0)
    do {
      perror("accept");
      exit(EXIT_FAILURE);
    } while (0);
  printf("ip=%s port=%d\n", inet_ntoa(peeraddr.sin_addr),
         ntohs(peeraddr.sin_port));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1223 <main+0x53>
jmp    1209 <main+0x39>
lea    0xdf0(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1444,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    0x2d31(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12b1 <main+0xe1>
jmp    1297 <main+0xc7>
lea    0xd69(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    12eb <main+0x11b>
jmp    12d1 <main+0x101>
lea    0xd3a(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jge    1325 <main+0x155>
jmp    130b <main+0x13b>
lea    0xd05(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1360 <main+0x190>
jmp    1346 <main+0x176>
lea    0xcd1(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xca4(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     12d5 <main+0x105>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1444,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     12de <main+0x10e>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     12e7 <main+0x117>
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1090 <listen@plt>
test   %rax,%rax
js     12f0 <main+0x120>
lea    0x20(%rsp),%rsi
lea    0x2c(%rsp),%rdx
mov    %ebx,%edi
call   10d0 <accept@plt>
test   %eax,%eax
js     12f9 <main+0x129>
mov    0x24(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10a0 <ntohs@plt>
lea    0xd62(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xd24(%rip),%rdi
jmp    1300 <main+0x130>
lea    0xd22(%rip),%rdi
jmp    1300 <main+0x130>
lea    0xd24(%rip),%rdi
jmp    1300 <main+0x130>
lea    0xd20(%rip),%rdi
jmp    1300 <main+0x130>
lea    0xd1e(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@.str.2 = [5 x i8] c"bind\00"
@SOMAXCONN = global i32 0
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@.str.5 = [15 x i8] c"ip=%s port=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %0
br label %13
13: ; preds = %12
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 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, %0
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 5188)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
store i32 1, i32* %4
%28 = load i32, i32* %2
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = call i64 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %4, i32 4)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %18
br label %34
34: ; preds = %33
%35 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %18
%40 = load i32, i32* %2
%41 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%42 = call i64 @bind(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %39
br label %45
45: ; preds = %44
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; No predecessors!
br label %50
50: ; preds = %49, %39
%51 = load i32, i32* %2
%52 = load i32, i32* @SOMAXCONN
%53 = call i64 @listen(i32 %51, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %50
br label %56
56: ; preds = %55
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; No predecessors!
br label %61
61: ; preds = %60, %50
%62 = load i32, i32* %2
%63 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %6)
store i32 %64, i32* %7
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %61
br label %67
67: ; preds = %66
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; No predecessors!
br label %72
72: ; preds = %71, %61
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i8* @inet_ntoa(i32 %75)
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @ntohs(i32 %78)
%80 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %76, i32 %79)
ret i32 0
}

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