#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 SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open_udp_socket();
int /*<<< orphan*/ stderr;
int socket_open(char *hostIP, char *port, int mode) {
  int sockfd;
  if (mode == SOCK_DGRAM) {
    if ((sockfd = open_udp_socket()) < 0) {
      fprintf(stderr,
              "Error opening UDP socket for host %s. Exiting program\n\n",
              hostIP);
      exit(1);
    }
  } else {
    return (-1);
  }
  return (sockfd);
}


x86 assembly (clang, -O0):
<socket_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    1190 <socket_open+0x60>
mov    $0x0,%al
call   1030 <open_udp_socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    118b <socket_open+0x5b>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    119c <socket_open+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <socket_open+0x72>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_open>:
push   %rbx
mov    0x2eb0(%rip),%rcx
mov    $0xffffffff,%eax
cmp    %edx,(%rcx)
jne    114f <socket_open+0x1f>
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <open_udp_socket@plt>
test   %eax,%eax
js     1151 <socket_open+0x21>
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [56 x i8] c"Error opening UDP socket for host %s. Exiting program\0A\0A\00"
define i32 @socket_open(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = load i32, i32* @SOCK_DGRAM
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = call i32 (...) @open_udp_socket()
store i32 %13, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
br label %22
21: ; preds = %3
store i32 -1, i32* %4
br label %24
22: ; preds = %20
%23 = load i32, i32* %8
store i32 %23, i32* %4
br label %24
24: ; preds = %22, %21
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [56 x i8] c"Error opening UDP socket for host %s. Exiting program\0A\0A\00"
define i32 @socket_open(i8* %0, i8* nocapture readnone %1, i32 %2) {
%4 = load i32, i32* @SOCK_DGRAM
%5 = icmp eq i32 %4, %2
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i32 (...) @open_udp_socket()
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %3
%14 = phi i32 [ -1, %3 ], [ %7, %6 ]
ret i32 %14
}