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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ DEBUGF(char *, ...);
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int udp_open() {
  int new_sock;
  DEBUGF("Entered udp_open\n");
  new_sock = (int)socket(AF_INET, SOCK_DGRAM, 0);
  if (new_sock < 0) {
    DEBUGF("socket call failed.\n");
    return -1;
  }
  DEBUGF("Socket open successful, sd: %d\n", new_sock);
  return new_sock;
}


x86 assembly (clang, -O0):
<udp_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1176 <udp_open+0x56>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <udp_open+0x6d>
mov    -0x8(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <DEBUGF@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_open>:
push   %rbx
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <DEBUGF@plt>
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %rax,%rbx
test   %ebx,%ebx
js     1161 <udp_open+0x41>
lea    0xed1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <DEBUGF@plt>
jmp    1174 <udp_open+0x54>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1030 <DEBUGF@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Entered udp_open\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [21 x i8] c"socket call failed.\0A\00"
@.str.2 = [32 x i8] c"Socket open successful, sd: %d\0A\00"
define i32 @udp_open() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i64 @socket(i32 %4, i32 %5, i32 0)
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
store i32 %15, i32* %1
br label %16
16: ; preds = %12, %10
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [18 x i8] c"Entered udp_open\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [21 x i8] c"socket call failed.\0A\00"
@.str.2 = [32 x i8] c"Socket open successful, sd: %d\0A\00"
define i32 @udp_open() {
%1 = tail call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = tail call i64 @socket(i32 %2, i32 %3, i32 0)
%5 = trunc i64 %4 to i32
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @DEBUGF(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ -1, %7 ], [ %5, %9 ]
ret i32 %12
}