#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*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int getBroadcastSocket() {
  static int sock = 0;
  if (sock == 0) {
    sock = socket(PF_INET, SOCK_DGRAM, 0);
    if (sock < 0) {
      perror("Error creating socket.");
      exit(1);
    }
  }
  return sock;
}


x86 assembly (clang, -O0):
<getBroadcastSocket>:
push   %rbp
mov    %rsp,%rbp
cmpl   $0x0,0x2f01(%rip)
jne    1188 <getBroadcastSocket+0x58>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,0x2edc(%rip)
cmpl   $0x0,0x2ed5(%rip)
jge    1183 <getBroadcastSocket+0x53>
lea    0xe8c(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    1188 <getBroadcastSocket+0x58>
mov    0x2eae(%rip),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBroadcastSocket>:
push   %rax
mov    0x2f05(%rip),%eax
test   %eax,%eax
jne    115e <getBroadcastSocket+0x2e>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,0x2ee2(%rip)
test   %eax,%eax
js     1160 <getBroadcastSocket+0x30>
pop    %rcx
ret
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@getBroadcastSocket.sock = internal global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [23 x i8] c"Error creating socket.\00"
define i32 @getBroadcastSocket() {
%1 = load i32, i32* @getBroadcastSocket.sock
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* @getBroadcastSocket.sock
%7 = load i32, i32* @getBroadcastSocket.sock
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %3
br label %13
13: ; preds = %12, %0
%14 = load i32, i32* @getBroadcastSocket.sock
ret i32 %14
}

LLVM IR (-O2):
@getBroadcastSocket.sock = internal unnamed_addr global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [23 x i8] c"Error creating socket.\00"
define i32 @getBroadcastSocket() {
%1 = load i32, i32* @getBroadcastSocket.sock
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* @getBroadcastSocket.sock
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3, %0
%12 = phi i32 [ %6, %3 ], [ %1, %0 ]
ret i32 %12
}