#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 */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ *ai_addr;
  int /*<<< orphan*/ *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_protocol;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int AI_NUMERICSERV;
int AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int setupUdpOrig(char sendingPort[6]) {
  int socket_fd, ecode;
  struct sockaddr_in *s_in;
  struct addrinfo hints, *addrlist;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  ecode = getaddrinfo(NULL, sendingPort, &hints, &addrlist);
  if (ecode != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ecode));
    exit(1);
  }
  s_in = (struct sockaddr_in *)addrlist->ai_addr;
  socket_fd = socket(addrlist->ai_family, addrlist->ai_socktype, 0);
  if (socket_fd < 0) {
    perror("recv_udp:socket");
    exit(1);
  }
  if (bind(socket_fd, (struct sockaddr *)s_in, sizeof(struct sockaddr_in)) <
      0) {
    perror("recv_udp:bind");
    exit(1);
  }
  return socket_fd;
}


x86 assembly (clang, -O0):
<setupUdpOrig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    0x2e1c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     123b <setupUdpOrig+0xbb>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xdd4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    127f <setupUdpOrig+0xff>
lea    0xda1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    12b0 <setupUdpOrig+0x130>
lea    0xd80(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupUdpOrig>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e3a(%rip),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movups %xmm0,0x28(%rsp)
mov    %rsp,%rcx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    1226 <setupUdpOrig+0xa6>
mov    (%rsp),%rax
mov    0x10(%rax),%rbx
mov    0x4(%rax),%esi
mov    0x8(%rax),%edi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1251 <setupUdpOrig+0xd1>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     125a <setupUdpOrig+0xda>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d93(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xdc3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdb9(%rip),%rdi
jmp    1261 <setupUdpOrig+0xe1>
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32*, i32*, i32*, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AI_NUMERICSERV = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [16 x i8] c"recv_udp:socket\00"
@.str.2 = [14 x i8] c"recv_udp:bind\00"
define i32 @setupUdpOrig(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
store i8* %0, i8** %2
%8 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 48)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_DGRAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @AI_NUMERICSERV
%14 = load i32, i32* @AI_PASSIVE
%15 = or i32 %13, %14
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32* null, i32** %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32* null, i32** %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32* null, i32** %20
%21 = load i8*, i8** %2
%22 = call i32 @getaddrinfo(i32* null, i8* %21, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %1
%26 = load i32, i32* @stderr
%27 = load i32, i32* %4
%28 = call i8* @gai_strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %1
%32 = load %struct.addrinfo*, %struct.addrinfo** %7
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 3
%34 = load i32*, i32** %33
%35 = bitcast i32* %34 to %struct.sockaddr_in*
store %struct.sockaddr_in* %35, %struct.sockaddr_in** %5
%36 = load %struct.addrinfo*, %struct.addrinfo** %7
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = load %struct.addrinfo*, %struct.addrinfo** %7
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = call i32 @socket(i32 %38, i32 %41, i32 0)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %31
%46 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %31
%49 = load i32, i32* %3
%50 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%51 = bitcast %struct.sockaddr_in* %50 to %struct.sockaddr*
%52 = call i64 @bind(i32 %49, %struct.sockaddr* %51, i32 4)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32*, i32*, i32*, i64 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AI_NUMERICSERV = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [16 x i8] c"recv_udp:socket\00"
@.str.2 = [14 x i8] c"recv_udp:bind\00"
define i32 @setupUdpOrig(i8* %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo* %2 to i8*
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 48)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_DGRAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @AI_NUMERICSERV
%12 = load i32, i32* @AI_PASSIVE
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
%16 = bitcast i32** %15 to i8*
%17 = call i32 @getaddrinfo(i32* null, i8* %0, %struct.addrinfo* %2, %struct.addrinfo** %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = call i8* @gai_strerror(i32 %17)
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %1
%25 = load %struct.addrinfo*, %struct.addrinfo** %3
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 3
%27 = bitcast i32** %26 to %struct.sockaddr**
%28 = load %struct.sockaddr*, %struct.sockaddr** %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @socket(i32 %30, i32 %32, i32 0)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %24
%39 = call i64 @bind(i32 %33, %struct.sockaddr* %28, i32 4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %38
ret i32 %33
}