#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*/ SOCK_DGRAM;
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ puts(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int CreateUdpSocket() {
  int n;
  if ((n = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    do {
      strerror(errno);
      puts("\n");
      err_quit("socket error");
    } while (1);
  return n;
}


x86 assembly (clang, -O0):
<CreateUdpSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11ac <CreateUdpSocket+0x6c>
jmp    1172 <CreateUdpSocket+0x32>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
call   1040 <err_quit@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1172 <CreateUdpSocket+0x32>
jmp    11a7 <CreateUdpSocket+0x67>
jmp    11ac <CreateUdpSocket+0x6c>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateUdpSocket>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     1168 <CreateUdpSocket+0x28>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e61(%rip),%r15
lea    0xe8a(%rip),%r14
lea    0xe85(%rip),%rbx
nopl   (%rax)
mov    (%r15),%edi
call   1050 <strerror@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <err_quit@plt>
jmp    1180 <CreateUdpSocket+0x40>

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [13 x i8] c"socket error\00"
define i32 @CreateUdpSocket() {
%1 = alloca i32
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = call i32 @socket(i32 %2, i32 %3, i32 0)
store i32 %4, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0
br label %7
7: ; preds = %12, %6
%8 = load i32, i32* @errno
%9 = call i32 @strerror(i32 %8)
%10 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @err_quit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %7
br i1 true, label %7, label %13
13: ; preds = %12
br label %14
14: ; preds = %13, %0
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [13 x i8] c"socket error\00"
define i32 @CreateUdpSocket() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_DGRAM
%3 = tail call i32 @socket(i32 %1, i32 %2, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0, %5
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @err_quit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %5
10: ; preds = %0
ret i32 %3
}