#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*/ IPPROTO_RAW;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int get_sockfd() {
  int sockfd = -1;
  if (sockfd == -1) {
    if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1) {
      perror("user: socket creating failed");
      return (-1);
    }
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<get_sockfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1182 <get_sockfd+0x62>
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    117d <get_sockfd+0x5d>
lea    0xe94(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <get_sockfd+0x68>
jmp    1182 <get_sockfd+0x62>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sockfd>:
push   %rbx
mov    0x2ec0(%rip),%rax
mov    (%rax),%edi
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    0x2e96(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     114c <get_sockfd+0x2c>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xead(%rip),%rdi
call   1030 <perror@plt>
jmp    1148 <get_sockfd+0x28>

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [29 x i8] c"user: socket creating failed\00"
define i32 @get_sockfd() {
%1 = alloca i32
%2 = alloca i32
store i32 -1, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_RAW
%8 = load i32, i32* @IPPROTO_RAW
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
13: ; preds = %5
br label %14
14: ; preds = %13, %0
%15 = load i32, i32* %2
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [29 x i8] c"user: socket creating failed\00"
define i32 @get_sockfd() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_RAW
%3 = load i32, i32* @IPPROTO_RAW
%4 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %0, %6
ret i32 %4
}