#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;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ ClearWinSock();
int /*<<< orphan*/ ErrorHandler(char *);
scalar_t__ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int bindIp(int socket, struct sockaddr_in *sad, size_t sadSize) {
  int result = 0;
  if (bind(socket, (struct sockaddr *)sad, (socklen_t)sadSize) < 0) {
    ErrorHandler("bind() failed.\n");
    close(socket);
    ClearWinSock();
    result = 1;
  }
  return (result);
}


x86 assembly (clang, -O0):
<bindIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    1198 <bindIp+0x58>
lea    0xe83(%rip),%rdi
call   1050 <ErrorHandler@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    $0x0,%al
call   1040 <ClearWinSock@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindIp>:
push   %rbx
mov    %edi,%ebx
call   1060 <bind@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1154 <bindIp+0x14>
pop    %rbx
ret
lea    0xea5(%rip),%rdi
call   1050 <ErrorHandler@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
call   1040 <ClearWinSock@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"bind() failed.\0A\00"
define i32 @bindIp(i32 %0, %struct.sockaddr_in* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%10 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%11 = load i64, i64* %6
%12 = trunc i64 %11 to i32
%13 = call i64 @bind(i32 %8, %struct.sockaddr* %10, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = call i32 @ErrorHandler(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
%19 = call i32 (...) @ClearWinSock()
store i32 1, i32* %7
br label %20
20: ; preds = %15, %3
%21 = load i32, i32* %7
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"bind() failed.\0A\00"
define i32 @bindIp(i32 %0, %struct.sockaddr_in* %1, i64 %2) {
%4 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%5 = trunc i64 %2 to i32
%6 = tail call i64 @bind(i32 %0, %struct.sockaddr* %4, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i32 @ErrorHandler(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @close(i32 %0)
%11 = tail call i32 (...) @ClearWinSock()
br label %12
12: ; preds = %8, %3
%13 = phi i32 [ 1, %8 ], [ 0, %3 ]
ret i32 %13
}