#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*/ enabled;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ lin_rsk_close(int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int lin_rsk_create() {
  int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  int enabled = 1;
  if (sockfd != -1) {
    if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &enabled, sizeof(enabled)) ==
        -1) {
      perror("setsockopt");
      lin_rsk_close(sockfd);
      return -1;
    }
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<lin_rsk_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11ce <lin_rsk_create+0x8e>
mov    -0x8(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11c9 <lin_rsk_create+0x89>
lea    0xe50(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%edi
call   1040 <lin_rsk_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <lin_rsk_create+0x94>
jmp    11ce <lin_rsk_create+0x8e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lin_rsk_create>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
movl   $0x1,0x4(%rsp)
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11a2 <lin_rsk_create+0x62>
mov    %eax,%ebp
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     11ab <lin_rsk_create+0x6b>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    %ebp,%edi
call   1040 <lin_rsk_close@plt>
jmp    11a2 <lin_rsk_create+0x62>

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

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