#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*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int open_sender(int *sender, int port, struct sockaddr_in remaddr,
                socklen_t remaddr_size) {
  *sender = socket(AF_INET, SOCK_DGRAM, 0);
  if (sender < 0) {
    return -1;
  }
  if (bind(*sender, (struct sockaddr *)&remaddr, remaddr_size) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<open_sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edx,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
jae    116d <open_sender+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <open_sender+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <bind@plt>
cmp    $0x0,%rax
jge    1195 <open_sender+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <open_sender+0x7c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sender>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdi,%rbx
mov    %edx,(%rsp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%edi
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,(%rbx)
mov    %rsp,%rsi
mov    %eax,%edi
mov    %ebp,%edx
call   1030 <bind@plt>
sar    $0x3f,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 @open_sender(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %2, i32* %10
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = load i32*, i32** %7
store i32 %13, i32* %14
%15 = load i32*, i32** %7
%16 = icmp ult i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %27
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%22 = load i32, i32* %9
%23 = call i64 @bind(i32 %20, %struct.sockaddr* %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 -1, i32* %5
br label %27
26: ; preds = %18
store i32 0, i32* %5
br label %27
27: ; preds = %26, %25, %17
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @open_sender(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %2, i32* %6
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %0
%10 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%11 = call i64 @bind(i32 %9, %struct.sockaddr* %10, i32 %3)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
ret i32 %13
}