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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int bind_portmap(void) {
  int sock = socket(PF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in sin;
  if (sock < 0)
    return -1;
  memset(&sin, 0, sizeof sin);
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl(0x7f000001);
  sin.sin_port = htons(111);
  if (bind(sock, (struct sockaddr *)&sin, sizeof sin) < 0) {
    int err = errno;
    close(sock);
    errno = err;
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<bind_portmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119a <bind_portmap+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <bind_portmap+0xbd>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x7f000001,%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    $0x6f,%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1217 <bind_portmap+0xb7>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%ecx
mov    0x2dc7(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <bind_portmap+0xbd>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_portmap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11f7 <bind_portmap+0x97>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x7f000001,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x6f,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     11e3 <bind_portmap+0x83>
mov    %ebp,%ebx
jmp    11f7 <bind_portmap+0x97>
mov    0x2de6(%rip),%r14
mov    (%r14),%r15d
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r15d,(%r14)
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@errno = global i32 0
define i32 @bind_portmap() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %31
11: ; preds = %0
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htonl(i32 2130706433)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 @htons(i32 111)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i64 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %11
%25 = load i32, i32* @errno
store i32 %25, i32* %4
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %4
store i32 %28, i32* @errno
store i32 -1, i32* %1
br label %31
29: ; preds = %11
%30 = load i32, i32* %2
store i32 %30, i32* %1
br label %31
31: ; preds = %29, %24, %10
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@errno = global i32 0
define i32 @bind_portmap() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @PF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = icmp slt i32 %4, 0
br i1 %6, label %21, label %7
7: ; preds = %0
%8 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htonl(i32 2130706433)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %11, i32* %12
%13 = call i32 @htons(i32 111)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %13, i32* %14
%15 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%16 = call i64 @bind(i32 %4, %struct.sockaddr* %15, i32 12)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %7
%19 = load i32, i32* @errno
%20 = call i32 @close(i32 %4)
store i32 %19, i32* @errno
br label %21
21: ; preds = %7, %0, %18
%22 = phi i32 [ -1, %18 ], [ -1, %0 ], [ %4, %7 ]
ret i32 %22
}