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

/* 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 setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int lin_rsk_lo_create() {
  int yes = 1;
  int sk = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  if (sk != -1) {
    if (setsockopt(sk, IPPROTO_IP, IP_HDRINCL, &yes, sizeof(yes)) == -1) {
      lin_rsk_close(sk);
      return -1;
    }
  }
  return sk;
}


x86 assembly (clang, -O0):
<lin_rsk_lo_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x8(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11b2 <lin_rsk_lo_create+0x82>
mov    -0xc(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11ad <lin_rsk_lo_create+0x7d>
mov    -0xc(%rbp),%edi
call   1040 <lin_rsk_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <lin_rsk_lo_create+0x88>
jmp    11b2 <lin_rsk_lo_create+0x82>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lin_rsk_lo_create>:
push   %rbp
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     119b <lin_rsk_lo_create+0x6b>
mov    %eax,%ebp
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1194 <lin_rsk_lo_create+0x64>
mov    %ebp,%ebx
jmp    119b <lin_rsk_lo_create+0x6b>
mov    %ebp,%edi
call   1040 <lin_rsk_close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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
define i32 @lin_rsk_lo_create() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %2
%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* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %0
%11 = load i32, i32* %3
%12 = load i32, i32* @IPPROTO_IP
%13 = load i32, i32* @IP_HDRINCL
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %2, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %3
%18 = call i32 @lin_rsk_close(i32 %17)
store i32 -1, i32* %1
br label %22
19: ; preds = %10
br label %20
20: ; preds = %19, %0
%21 = load i32, i32* %3
store i32 %21, i32* %1
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* %1
ret i32 %23
}

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
define i32 @lin_rsk_lo_create() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_RAW
%5 = load i32, i32* @IPPROTO_TCP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %0
%9 = load i32, i32* @IPPROTO_IP
%10 = load i32, i32* @IP_HDRINCL
%11 = call i32 @setsockopt(i32 %6, i32 %9, i32 %10, i32* %1, i32 4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @lin_rsk_close(i32 %6)
br label %15
15: ; preds = %0, %8, %13
%16 = phi i32 [ -1, %13 ], [ %6, %8 ], [ -1, %0 ]
ret i32 %16
}