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

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETH_P_ARP;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int timer_kmalloc() {
  int s = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_ARP));
  if (s == -1) {
    perror("socket(SOCK_DGRAM)");
    exit(EXIT_FAILURE);
  }
  return s;
}


x86 assembly (clang, -O0):
<timer_kmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    %eax,%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a2 <timer_kmalloc+0x62>
lea    0xe71(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_kmalloc>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%ebx
mov    0x2e95(%rip),%rax
mov    (%rax),%ebp
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <socket@plt>
cmp    $0xffffffff,%eax
je     117a <timer_kmalloc+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@AF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@ETH_P_ARP = global i32 0
@.str = [19 x i8] c"socket(SOCK_DGRAM)\00"
@EXIT_FAILURE = global i32 0
define i32 @timer_kmalloc() {
%1 = alloca i32
%2 = load i32, i32* @AF_PACKET
%3 = load i32, i32* @SOCK_DGRAM
%4 = load i32, i32* @ETH_P_ARP
%5 = call i32 @htons(i32 %4)
%6 = call i32 @socket(i32 %2, i32 %3, i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@AF_PACKET = global i32 0
@SOCK_DGRAM = global i32 0
@ETH_P_ARP = global i32 0
@.str = [19 x i8] c"socket(SOCK_DGRAM)\00"
@EXIT_FAILURE = global i32 0
define i32 @timer_kmalloc() {
%1 = load i32, i32* @AF_PACKET
%2 = load i32, i32* @SOCK_DGRAM
%3 = load i32, i32* @ETH_P_ARP
%4 = tail call i32 @htons(i32 %3)
%5 = tail call i32 @socket(i32 %1, i32 %2, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
ret i32 %5
}