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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
void *htons(int);
int /*<<< orphan*/ logger(char *, int, int /*<<< orphan*/, char *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int setup_test_socket(int *fd, struct sockaddr_in *addr) {
  int ret = 0;
  memset(addr, 0, sizeof(struct sockaddr_in));
  addr->sin_family = AF_INET;
  addr->sin_port = htons(12000);
  addr->sin_addr.s_addr = htons(INADDR_ANY);
  *fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (*fd < 0) {
    logger("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/"
           "i8-transceiver/i8-transceiver.c",
           742, 0, "Failed to create test-socket: socket: %s", strerror(errno));
    return -1;
  }
  ret = bind(*fd, (struct sockaddr *)addr, sizeof(struct sockaddr_in));
  if (ret) {
    logger("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/"
           "i8-transceiver/i8-transceiver.c",
           750, 0, "Failed to bind test socket: bind: %s", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_test_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    $0x2ee0,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1230 <setup_test_socket+0xd0>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%r8d
lea    0xdef(%rip),%rdi
mov    $0x2e6,%esi
xor    %edx,%edx
lea    0xe80(%rip),%rcx
call   1050 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <setup_test_socket+0x12f>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    $0x18,%edx
call   1060 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1288 <setup_test_socket+0x128>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%r8d
lea    0xd97(%rip),%rdi
mov    $0x2ee,%esi
xor    %edx,%edx
lea    0xe51(%rip),%rcx
call   1050 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <setup_test_socket+0x12f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_test_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %r15d,%r15d
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e62(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rbx)
mov    $0x2ee0,%edi
call   1030 <htons@plt>
mov    %rax,0x8(%rbx)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %rax,(%rbx)
mov    0x0(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,(%r14)
test   %eax,%eax
js     1202 <setup_test_socket+0xa2>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1060 <bind@plt>
test   %eax,%eax
je     1233 <setup_test_socket+0xd3>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe0c(%rip),%rdi
lea    0xecd(%rip),%rcx
mov    $0x2ee,%esi
jmp    1223 <setup_test_socket+0xc3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xde9(%rip),%rdi
lea    0xe81(%rip),%rcx
mov    $0x2e6,%esi
xor    %edx,%edx
mov    %eax,%r8d
call   1050 <logger@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/i8-transceiver/i8-transceiver.c\00"
@.str.1 = [41 x i8] c"Failed to create test-socket: socket: %s\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"Failed to bind test socket: bind: %s\00"
define i32 @setup_test_socket(i32* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
store i32* %0, i32** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i32 0, i32* %6
%7 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%8 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 24)
%9 = load i32, i32* @AF_INET
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %9, i32* %11
%12 = call i8* @htons(i32 12000)
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i8* %12, i8** %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i8* @htons(i32 %15)
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i8* %16, i8** %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = load i32, i32* @IPPROTO_UDP
%23 = call i32 @socket(i32 %20, i32 %21, i32 %22)
%24 = load i32*, i32** %4
store i32 %23, i32* %24
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = call i32 @logger(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i32 742, i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 -1, i32* %3
br label %45
32: ; preds = %2
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%36 = bitcast %struct.sockaddr_in* %35 to %struct.sockaddr*
%37 = call i32 @bind(i32 %34, %struct.sockaddr* %36, i32 24)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 @logger(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i32 750, i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %42)
store i32 -1, i32* %3
br label %45
44: ; preds = %32
store i32 0, i32* %3
br label %45
45: ; preds = %44, %40, %28
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/i8-transceiver/i8-transceiver.c\00"
@.str.1 = [41 x i8] c"Failed to create test-socket: socket: %s\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"Failed to bind test socket: bind: %s\00"
define i32 @setup_test_socket(i32* nocapture writeonly %0, %struct.sockaddr_in* %1) {
%3 = tail call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 24)
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %4, i32* %5
%6 = tail call i8* @htons(i32 12000)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i8* %6, i8** %7
%8 = load i32, i32* @INADDR_ANY
%9 = tail call i8* @htons(i32 %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i8* %9, i8** %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = load i32, i32* @IPPROTO_UDP
%14 = tail call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %0
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 @logger(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i32 742, i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %28
20: ; preds = %2
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = tail call i32 @bind(i32 %14, %struct.sockaddr* %21, i32 24)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @errno
%26 = tail call i32 @strerror(i32 %25)
%27 = tail call i32 @logger(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i32 750, i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %20, %24, %16
%29 = phi i32 [ -1, %16 ], [ -1, %24 ], [ 0, %20 ]
ret i32 %29
}