#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(int /*<<< orphan*/);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main22() {
  int serv_sock;
  if ((serv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) < 0)) {
    perror("socket init error.");
    return 1;
  }
  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5555);
  server_addr.sin_addr.s_addr = inet_addr(INADDR_ANY);
  if (bind(serv_sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("connect error.");
    return 1;
  }
  if (listen(serv_sock, 5) < 0) {
    perror("listen error.");
    return 1;
  }
  socklen_t clent_addr_size = sizeof(client_addr);
  int client_sock = accept(serv_sock, (struct sockaddr *)&client_addr,
                           (socklen_t *)&clent_addr_size);
  if (client_sock < 0) {
    perror("accept error.");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main22>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x8(%rbp)
test   $0x1,%al
jne    11c7 <main22+0x47>
jmp    11df <main22+0x5f>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main22+0x13e>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x15b3,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1050 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    124c <main22+0xcc>
lea    0xdd8(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main22+0x13e>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    127b <main22+0xfb>
lea    0xdb8(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main22+0x13e>
movl   $0xc,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12b7 <main22+0x137>
lea    0xd8a(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main22+0x13e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main22>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e58(%rip),%r15
mov    (%r15),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
test   %rax,%rax
js     1244 <main22+0xc4>
mov    %rax,%rbx
shr    $0x3f,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x15b3,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1050 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     124d <main22+0xcd>
mov    %ebx,%edi
mov    $0x5,%esi
call   1060 <listen@plt>
test   %rax,%rax
js     1256 <main22+0xd6>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jns    1267 <main22+0xe7>
lea    0xdee(%rip),%rdi
jmp    125d <main22+0xdd>
lea    0xdb5(%rip),%rdi
jmp    125d <main22+0xdd>
lea    0xdbf(%rip),%rdi
jmp    125d <main22+0xdd>
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [19 x i8] c"socket init error.\00"
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"connect error.\00"
@.str.2 = [14 x i8] c"listen error.\00"
@.str.3 = [14 x i8] c"accept error.\00"
define i32 @main22() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = load i32, i32* @IPPROTO_TCP
%10 = call i64 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i64 %10, 0
%12 = zext i1 %11 to i32
store i32 %12, i32* %2
br i1 %11, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %46
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 5555)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i32 @inet_addr(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %15
%30 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %46
31: ; preds = %15
%32 = load i32, i32* %2
%33 = call i64 @listen(i32 %32, i32 5)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
37: ; preds = %31
store i32 12, i32* %5
%38 = load i32, i32* %2
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%40 = call i32 @accept(i32 %38, %struct.sockaddr* %39, i32* %5)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %46
45: ; preds = %37
store i32 0, i32* %1
br label %46
46: ; preds = %45, %43, %35, %29, %13
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [19 x i8] c"socket init error.\00"
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"connect error.\00"
@.str.2 = [14 x i8] c"listen error.\00"
@.str.3 = [14 x i8] c"accept error.\00"
define i32 @main22() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = load i32, i32* @IPPROTO_TCP
%7 = tail call i64 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i64 %7, 0
%9 = lshr i64 %7, 63
%10 = trunc i64 %9 to i32
br i1 %8, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %45
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = bitcast %struct.sockaddr_in* %2 to i8*
%16 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 5555)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i32 @inet_addr(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i64 @bind(i32 %10, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %13
%28 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %43
29: ; preds = %13
%30 = call i64 @listen(i32 %10, i32 5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %43
34: ; preds = %29
%35 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%36 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%37 = call i32 @accept(i32 %10, %struct.sockaddr* %36, i32* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %34, %39
%42 = phi i32 [ 1, %39 ], [ 0, %34 ]
br label %43
43: ; preds = %41, %32, %27
%44 = phi i32 [ 1, %27 ], [ 1, %32 ], [ %42, %41 ]
br label %45
45: ; preds = %43, %11
%46 = phi i32 [ 1, %11 ], [ %44, %43 ]
ret i32 %46
}