#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*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int const *,
                      int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int create_raw_socket_tcp(void) {
  int sock;
  sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  if (sock < 0) {
    return sock;
  }
  int const one = 1;
  if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)) < 0) {
    fprintf(stderr, "[ERROR] "
                    "[CREATE_RAW_SOCKET_TCP] Unable to set option "
                    "\"IP_HDRINCL\" on the socket"
                    "\n");
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<create_raw_socket_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1170 <create_raw_socket_tcp+0x40>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cc <create_raw_socket_tcp+0x9c>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11c6 <create_raw_socket_tcp+0x96>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <create_raw_socket_tcp+0x9c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_raw_socket_tcp>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11a6 <create_raw_socket_tcp+0x76>
movl   $0x1,0xc(%rsp)
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    11a6 <create_raw_socket_tcp+0x76>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
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
@stderr = global i32 0
@.str = [81 x i8] c"[ERROR] [CREATE_RAW_SOCKET_TCP] Unable to set option \22IP_HDRINCL\22 on the socket\0A\00"
define i32 @create_raw_socket_tcp() {
%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
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = load i32, i32* %2
store i32 %11, i32* %1
br label %23
12: ; preds = %0
store i32 1, i32* %3
%13 = load i32, i32* %2
%14 = load i32, i32* @IPPROTO_IP
%15 = load i32, i32* @IP_HDRINCL
%16 = call i64 @setsockopt(i32 %13, i32 %14, i32 %15, i32* %3, i32 4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
21: ; preds = %12
%22 = load i32, i32* %2
store i32 %22, i32* %1
br label %23
23: ; preds = %21, %18, %10
%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
@stderr = global i32 0
@.str = [81 x i8] c"[ERROR] [CREATE_RAW_SOCKET_TCP] Unable to set option \22IP_HDRINCL\22 on the socket\0A\00"
define i32 @create_raw_socket_tcp() {
%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 = icmp slt i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %0
%8 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%9 = load i32, i32* @IPPROTO_IP
%10 = load i32, i32* @IP_HDRINCL
%11 = call i64 @setsockopt(i32 %5, i32 %9, i32 %10, i32* %1, i32 4)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %7, %13
%17 = phi i32 [ -1, %13 ], [ %5, %7 ]
br label %18
18: ; preds = %0, %16
%19 = phi i32 [ %17, %16 ], [ %5, %0 ]
ret i32 %19
}