#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;
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int __ipv4_udp_socket(struct sockaddr_in *addr) {
  int udp_socket;
  udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
  if (udp_socket == -1)
    return -1;
  if (bind(udp_socket, (struct sockaddr *)addr,
           (socklen_t)sizeof(struct sockaddr_in)) == -1)
    return -1;
  return udp_socket;
}


x86 assembly (clang, -O0):
<__ipv4_udp_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    115e <__ipv4_udp_socket+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <__ipv4_udp_socket+0x6a>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <bind@plt>
cmp    $0xffffffff,%eax
jne    1184 <__ipv4_udp_socket+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <__ipv4_udp_socket+0x6a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ipv4_udp_socket>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eba(%rip),%rax
mov    (%rax),%edi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
cmp    $0xffffffff,%eax
je     115e <__ipv4_udp_socket+0x3e>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <bind@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    1163 <__ipv4_udp_socket+0x43>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 @__ipv4_udp_socket(%struct.sockaddr_in* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in*
%4 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %20
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%14 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%15 = call i32 @bind(i32 %12, %struct.sockaddr* %14, i32 4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 -1, i32* %2
br label %20
18: ; preds = %11
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %17, %10
%21 = load i32, i32* %2
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 @__ipv4_udp_socket(%struct.sockaddr_in* %0) {
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = bitcast %struct.sockaddr_in* %0 to %struct.sockaddr*
%8 = tail call i32 @bind(i32 %4, %struct.sockaddr* %7, i32 4)
%9 = icmp eq i32 %8, -1
%10 = select i1 %9, i32 -1, i32 %4
br label %11
11: ; preds = %6, %1
%12 = phi i32 [ -1, %1 ], [ %10, %6 ]
ret i32 %12
}