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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
scalar_t__ sockaddrfill(struct sockaddr_in *, char const *, char const *,
                        int /*<<< orphan*/, int /*<<< orphan*/, int);
int udpstrlisten(int sock, const char *hostname, const char *service) {
  struct sockaddr_in sa;
  if (sockaddrfill(&sa, hostname, service, AF_INET, SOCK_DGRAM, 1) < 0) {
    return -1;
  }
  return bind(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
}


x86 assembly (clang, -O0):
<udpstrlisten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x2ea6(%rip),%rax
mov    (%rax),%ecx
mov    0x2e95(%rip),%rax
mov    (%rax),%r8d
lea    -0x20(%rbp),%rdi
mov    $0x1,%r9d
call   1030 <sockaddrfill@plt>
cmp    $0x0,%rax
jge    1173 <udpstrlisten+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <udpstrlisten+0x67>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpstrlisten>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%ecx
mov    0x2ea9(%rip),%rax
mov    (%rax),%r8d
lea    0x8(%rsp),%rdi
mov    $0x1,%r9d
call   1030 <sockaddrfill@plt>
test   %rax,%rax
js     1162 <udpstrlisten+0x42>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <bind@plt>
jmp    1167 <udpstrlisten+0x47>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @udpstrlisten(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %7
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i64 @sockaddrfill(%struct.sockaddr_in* %8, i8* %9, i8* %10, i32 %11, i32 %12, i32 1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %20
16: ; preds = %3
%17 = load i32, i32* %5
%18 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%19 = call i32 @bind(i32 %17, %struct.sockaddr* %18, i32 4)
store i32 %19, i32* %4
br label %20
20: ; preds = %16, %15
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @udpstrlisten(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i64 @sockaddrfill(%struct.sockaddr_in* %4, i8* %1, i8* %2, i32 %6, i32 %7, i32 1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%12 = call i32 @bind(i32 %0, %struct.sockaddr* %11, i32 4)
br label %13
13: ; preds = %3, %10
%14 = phi i32 [ %12, %10 ], [ -1, %3 ]
ret i32 %14
}