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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int init_socket(int *gsock) {
  int tmp, sock;
  char ip[32] = "0.0.0.0";
  struct sockaddr_in ins;
  memset(&ins, 0, sizeof(ins));
  ins.sin_family = AF_INET;
  ins.sin_port = htons(1024 + 25);
  if (!inet_aton(ip, &(ins.sin_addr))) {
    write(2, "broken ipn\n", 11);
    return 0;
  }
  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    perror("socket");
    return 0;
  }
  tmp = 1;
  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp)) == -1) {
    perror("setsockopt");
    return 0;
  }
  if (bind(sock, (struct sockaddr *)&ins, sizeof(ins)) == -1) {
    perror("bind");
    return 0;
  }
  if (listen(sock, 32) == -1) {
    perror("listen");
    return 0;
  }
  *gsock = sock;
  return 1;
}


x86 assembly (clang, -O0):
<init_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe57(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe54(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    $0x419,%edi
call   1050 <htons@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x0,%eax
jne    1229 <init_socket+0x99>
mov    $0x2,%edi
lea    0xe0d(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <init_socket+0x193>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1267 <init_socket+0xd7>
lea    0xdd6(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <init_socket+0x193>
movl   $0x1,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12b3 <init_socket+0x123>
lea    0xd91(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <init_socket+0x193>
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    12e5 <init_socket+0x155>
lea    0xd6a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <init_socket+0x193>
mov    -0x18(%rbp),%edi
mov    $0x20,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    1313 <init_socket+0x183>
lea    0xd41(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <init_socket+0x193>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_socket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
movaps 0xe6e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe52(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x419,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <inet_aton@plt>
test   %eax,%eax
je     127d <init_socket+0xed>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1295 <init_socket+0x105>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     12a3 <init_socket+0x113>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     12ac <init_socket+0x11c>
mov    %ebx,%edi
mov    $0x20,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
je     12b5 <init_socket+0x125>
mov    %ebx,(%r14)
mov    $0x1,%ebp
jmp    12c3 <init_socket+0x133>
lea    0xd9c(%rip),%rsi
mov    $0x2,%edi
mov    $0xb,%edx
call   1040 <write@plt>
jmp    12c3 <init_socket+0x133>
lea    0xd90(%rip),%rdi
call   10a0 <perror@plt>
jmp    12c3 <init_socket+0x133>
lea    0xd89(%rip),%rdi
jmp    12bc <init_socket+0x12c>
lea    0xd8b(%rip),%rdi
jmp    12bc <init_socket+0x12c>
lea    0xd87(%rip),%rdi
call   10a0 <perror@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.init_socket.ip = [32 x i8] c"0.0.0.0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@AF_INET = global i32 0
@.str = [12 x i8] c"broken ipn\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [11 x i8] c"setsockopt\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
define i32 @init_socket(i32* nocapture writeonly %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htons(i32 1049)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%14 = call i32 @inet_aton(i8* %6, i32* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
br label %44
18: ; preds = %1
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %44
25: ; preds = %18
store i32 1, i32* %2
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = call i32 @setsockopt(i32 %21, i32 %26, i32 %27, i32* %2, i32 4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %44
32: ; preds = %25
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @bind(i32 %21, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %44
38: ; preds = %32
%39 = call i32 @listen(i32 %21, i32 32)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %44
43: ; preds = %38
store i32 %21, i32* %0
br label %44
44: ; preds = %43, %41, %36, %30, %23, %16
%45 = phi i32 [ 0, %23 ], [ 0, %30 ], [ 0, %36 ], [ 0, %41 ], [ 1, %43 ], [ 0, %16 ]
ret i32 %45
}