#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 */
typedef int /*<<< orphan*/ one;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ pfatal(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int get_raw_fd() {
  int fd, ret, one;
  fd = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
  if (fd < 0)
    pfatal("socket");
  one = 1;
  ret = setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one));
  if (ret < 0)
    pfatal("setsockopt");
  return fd;
}


x86 assembly (clang, -O0):
<get_raw_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1171 <get_raw_fd+0x41>
lea    0xe94(%rip),%rdi
call   1040 <pfatal@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b5 <get_raw_fd+0x85>
lea    0xe57(%rip),%rdi
call   1040 <pfatal@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_raw_fd>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1167 <get_raw_fd+0x37>
lea    0xe9e(%rip),%rdi
call   1040 <pfatal@plt>
movl   $0x1,0xc(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    11a3 <get_raw_fd+0x73>
lea    0xe69(%rip),%rdi
call   1040 <pfatal@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@.str = [7 x i8] c"socket\00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
define i32 @get_raw_fd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_RAW
%6 = load i32, i32* @IPPROTO_ICMP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @pfatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
store i32 1, i32* %3
%13 = load i32, i32* %1
%14 = load i32, i32* @IPPROTO_IP
%15 = load i32, i32* @IP_HDRINCL
%16 = call i32 @setsockopt(i32 %13, i32 %14, i32 %15, i32* %3, i32 4)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @pfatal(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@.str = [7 x i8] c"socket\00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
define i32 @get_raw_fd() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_RAW
%5 = load i32, i32* @IPPROTO_ICMP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @pfatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
store i32 1, i32* %1
%11 = load i32, i32* @IPPROTO_IP
%12 = load i32, i32* @IP_HDRINCL
%13 = call i32 @setsockopt(i32 %6, i32 %11, i32 %12, i32* %1, i32 4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @pfatal(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
ret i32 %6
}