#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*/ IP_HDRINCL;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_msg(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int init_network() {
  int sc;
  int one = 1;
  int *val = &one;
  sc = socket(AF_INET, SOCK_RAW, 77);
  if (sc == -1) {
    log_msg(0, "Unable to open socket: %s.", strerror(errno));
    return (sc);
  }
  if (setsockopt(sc, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) == -1) {
    log_msg(0, "Unable to set IP_HDRINCL: %s.", strerror(errno));
    close(sc);
    return (-1);
  }
  return (sc);
}


x86 assembly (clang, -O0):
<init_network>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0xc(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    $0x4d,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b9 <init_network+0x69>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe57(%rip),%rsi
call   1050 <log_msg@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121e <init_network+0xce>
mov    -0x8(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1218 <init_network+0xc8>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe1c(%rip),%rsi
call   1050 <log_msg@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121e <init_network+0xce>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_network>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    $0x4d,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11d0 <init_network+0x80>
mov    %eax,%ebx
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11f3 <init_network+0xa3>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5d(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1050 <log_msg@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11ee <init_network+0x9e>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe1b(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1050 <log_msg@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
@.str = [27 x i8] c"Unable to open socket: %s.\00"
@errno = global i32 0
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [30 x i8] c"Unable to set IP_HDRINCL: %s.\00"
define i32 @init_network() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 1, i32* %3
store i32* %3, i32** %4
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_RAW
%7 = call i32 @socket(i32 %5, i32 %6, i32 77)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @log_msg(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
store i32 %14, i32* %1
br label %30
15: ; preds = %0
%16 = load i32, i32* %2
%17 = load i32, i32* @IPPROTO_IP
%18 = load i32, i32* @IP_HDRINCL
%19 = load i32*, i32** %4
%20 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %19, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @log_msg(i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
store i32 -1, i32* %1
br label %30
28: ; preds = %15
%29 = load i32, i32* %2
store i32 %29, i32* %1
br label %30
30: ; preds = %28, %22, %10
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [27 x i8] c"Unable to open socket: %s.\00"
@errno = global i32 0
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [30 x i8] c"Unable to set IP_HDRINCL: %s.\00"
define i32 @init_network() {
%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 = tail call i32 @socket(i32 %3, i32 %4, i32 77)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @log_msg(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %21
11: ; preds = %0
%12 = load i32, i32* @IPPROTO_IP
%13 = load i32, i32* @IP_HDRINCL
%14 = call i32 @setsockopt(i32 %5, i32 %12, i32 %13, i32* %1, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @log_msg(i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @close(i32 %5)
br label %21
21: ; preds = %11, %16, %7
%22 = phi i32 [ -1, %7 ], [ -1, %16 ], [ %5, %11 ]
ret i32 %22
}