#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fs_log(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setupUdpSocket(int port) {
  int sfd, retval;
  struct sockaddr_in myaddr;
  fs_log(LOG_INFO, "setup udp socket...");
  sfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sfd == -1) {
    fs_log(LOG_ERR, "socket");
    exit(EXIT_FAILURE);
  }
  memset(&myaddr, 0, sizeof(struct sockaddr));
  myaddr.sin_family = AF_INET;
  myaddr.sin_port = htons(port);
  myaddr.sin_addr.s_addr = INADDR_ANY;
  retval = bind(sfd, (struct sockaddr *)&myaddr, sizeof(struct sockaddr));
  if (retval == -1) {
    fs_log(LOG_ERR, "bind");
    exit(EXIT_FAILURE);
  }
  fs_log(LOG_INFO, "udp done![%d]", sfd);
  return sfd;
}


x86 assembly (clang, -O0):
<setupUdpSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1060 <fs_log@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cd <setupUdpSocket+0x6d>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1060 <fs_log@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1243 <setupUdpSocket+0xe3>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fs_log@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <fs_log@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupUdpSocket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    0x2e4a(%rip),%r15
mov    (%r15),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1060 <fs_log@plt>
mov    0x2e5a(%rip),%r12
mov    (%r12),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     1211 <setupUdpSocket+0xb1>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
cmp    $0xffffffff,%eax
je     1223 <setupUdpSocket+0xc3>
mov    (%r15),%edi
lea    0xe27(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fs_log@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
jmp    1233 <setupUdpSocket+0xd3>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
xor    %eax,%eax
call   1060 <fs_log@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@LOG_INFO = global i32 0
@.str = [20 x i8] c"setup udp socket...\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [14 x i8] c"udp done![%d]\00"
define i32 @setupUdpSocket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
%6 = load i32, i32* @LOG_INFO
%7 = call i32 (i32, i8*, ...) @fs_log(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @LOG_ERR
%15 = call i32 (i32, i8*, ...) @fs_log(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 4)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* %2
%23 = call i32 @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %3
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 4)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %18
%34 = load i32, i32* @LOG_ERR
%35 = call i32 (i32, i8*, ...) @fs_log(i32 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %18
%39 = load i32, i32* @LOG_INFO
%40 = load i32, i32* %3
%41 = call i32 (i32, i8*, ...) @fs_log(i32 %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@LOG_INFO = global i32 0
@.str = [20 x i8] c"setup udp socket...\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [14 x i8] c"udp done![%d]\00"
define i32 @setupUdpSocket(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @LOG_INFO
%5 = tail call i32 (i32, i8*, ...) @fs_log(i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @LOG_ERR
%12 = tail call i32 (i32, i8*, ...) @fs_log(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 4)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 %0)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%24 = call i32 @bind(i32 %8, %struct.sockaddr* %23, i32 4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @fs_log(i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %15
%32 = load i32, i32* @LOG_INFO
%33 = call i32 (i32, i8*, ...) @fs_log(i32 %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %8)
ret i32 %8
}