#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*/ myaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int socketBind() {
  struct sockaddr_in myaddr;
  int fd;
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("cannot create socket\n");
    return 0;
  }
  memset((char *)&myaddr, 0, sizeof(myaddr));
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  myaddr.sin_port = htons(4546);
  if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
    perror("bind failed");
    return 0;
  }
  puts("\n[SPECTRA Sensing Module]  Initialization done");
  return fd;
}


x86 assembly (clang, -O0):
<socketBind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b5 <socketBind+0x45>
lea    0xe5c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <socketBind+0xc4>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x11c2,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1222 <socketBind+0xb2>
lea    0xe05(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <socketBind+0xc4>
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketBind>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e67(%rip),%r15
mov    (%r15),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     1208 <socketBind+0x98>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x11c2,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     1216 <socketBind+0xa6>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf1(%rip),%rdi
call   1080 <perror@plt>
jmp    11fb <socketBind+0x8b>
lea    0xdf9(%rip),%rdi
call   1080 <perror@plt>
jmp    11fb <socketBind+0x8b>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [22 x i8] c"cannot create socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"bind failed\00"
@.str.2 = [47 x i8] c"\0A[SPECTRA Sensing Module] Initialization done\00"
define i32 @socketBind() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %30
10: ; preds = %0
%11 = bitcast %struct.sockaddr_in* %2 to i8*
%12 = call i32 @memset(i8* %11, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 4546)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %3
%22 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%23 = call i64 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %10
%26 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %30
27: ; preds = %10
%28 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %3
store i32 %29, i32* %1
br label %30
30: ; preds = %27, %25, %8
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [22 x i8] c"cannot create socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"bind failed\00"
@.str.2 = [47 x i8] c"\0A[SPECTRA Sensing Module] Initialization done\00"
define i32 @socketBind() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %0
%10 = call i32 @memset(i8* %2, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = call i32 @htons(i32 4546)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%19 = call i64 @bind(i32 %5, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %9
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %9
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21, %7
%26 = phi i32 [ 0, %7 ], [ 0, %21 ], [ %5, %23 ]
ret i32 %26
}