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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ DEBUGF(char *, ...);
int /*<<< orphan*/ INADDR_ANY;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int udp_bind(int fd, int portno) {
  struct sockaddr_in binder;
  DEBUGF("Entered udp_bind\n");
  binder.sin_family = AF_INET;
  binder.sin_addr.s_addr = INADDR_ANY;
  binder.sin_port = htons(portno);
  if (bind(fd, (struct sockaddr *)&binder, sizeof(binder))) {
    DEBUGF("bind call for socket [%d] failed.\n", fd);
    return -1;
  }
  DEBUGF("Binding successful for socket [%d]\n", fd);
  return 1;
}


x86 assembly (clang, -O0):
<udp_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
je     11a7 <udp_bind+0x77>
mov    -0x8(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <udp_bind+0x8f>
mov    -0x8(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_bind>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <DEBUGF@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1050 <bind@plt>
test   %rax,%rax
lea    0xead(%rip),%rcx
lea    0xe83(%rip),%rdi
cmove  %rcx,%rdi
neg    %rax
sbb    %ebp,%ebp
or     $0x1,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <DEBUGF@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"Entered udp_bind\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [35 x i8] c"bind call for socket [%d] failed.\0A\00"
@.str.2 = [36 x i8] c"Binding successful for socket [%d]\0A\00"
define i32 @udp_bind(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* %5
%14 = call i32 @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* %4
%17 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%18 = call i64 @bind(i32 %16, %struct.sockaddr* %17, i32 12)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 -1, i32* %3
br label %26
23: ; preds = %2
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 1, i32* %3
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"Entered udp_bind\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [35 x i8] c"bind call for socket [%d] failed.\0A\00"
@.str.2 = [36 x i8] c"Binding successful for socket [%d]\0A\00"
define i32 @udp_bind(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @INADDR_ANY
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 %1)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%13 = call i64 @bind(i32 %0, %struct.sockaddr* %12, i32 12)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0)
%16 = select i1 %14, i32 1, i32 -1
%17 = call i32 (i8*, ...) @DEBUGF(i8* %15, i32 %0)
ret i32 %16
}