#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*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int rpcbind_socket(void) {
  static int my_udpsock = -1;
  if (my_udpsock >= 0)
    return my_udpsock;
  if ((my_udpsock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("unable to create socket");
    return -1;
  }
  return my_udpsock;
}


x86 assembly (clang, -O0):
<rpcbind_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f01(%rip)
jl     1143 <rpcbind_socket+0x23>
mov    0x2ef5(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <rpcbind_socket+0x6c>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,0x2ece(%rip)
cmp    $0x0,%eax
jge    1183 <rpcbind_socket+0x63>
lea    0xe8e(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <rpcbind_socket+0x6c>
mov    0x2ea7(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpcbind_socket>:
push   %rax
mov    0x2f09(%rip),%eax
test   %eax,%eax
js     112d <rpcbind_socket+0xd>
pop    %rcx
ret
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,0x2ee4(%rip)
test   %eax,%eax
jns    112b <rpcbind_socket+0xb>
lea    0xea9(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@rpcbind_socket.my_udpsock = internal global i32 -1
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [24 x i8] c"unable to create socket\00"
define i32 @rpcbind_socket() {
%1 = alloca i32
%2 = load i32, i32* @rpcbind_socket.my_udpsock
%3 = icmp sge i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = load i32, i32* @rpcbind_socket.my_udpsock
store i32 %5, i32* %1
br label %15
6: ; preds = %0
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* @rpcbind_socket.my_udpsock
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %15
13: ; preds = %6
%14 = load i32, i32* @rpcbind_socket.my_udpsock
store i32 %14, i32* %1
br label %15
15: ; preds = %13, %11, %4
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@rpcbind_socket.my_udpsock = internal unnamed_addr global i32 -1
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [24 x i8] c"unable to create socket\00"
define i32 @rpcbind_socket() {
%1 = load i32, i32* @rpcbind_socket.my_udpsock
%2 = icmp sgt i32 %1, -1
br i1 %2, label %10, label %3
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* @rpcbind_socket.my_udpsock
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %3, %0, %8
%11 = phi i32 [ -1, %8 ], [ %1, %0 ], [ %6, %3 ]
ret i32 %11
}