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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_TIMESTAMP;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int ping_open() {
  int s;
  if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
    return -1;
  int opt = 1;
  setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt));
  return s;
}


x86 assembly (clang, -O0):
<ping_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1160 <ping_open+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <ping_open+0x71>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ping_open>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
test   %eax,%eax
js     1179 <ping_open+0x59>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2e8e(%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>
jmp    117e <ping_open+0x5e>
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_ICMP = global i32 0
@SOL_SOCKET = global i32 0
@SO_TIMESTAMP = global i32 0
define i32 @ping_open() {
%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_ICMP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %16
10: ; preds = %0
store i32 1, i32* %3
%11 = load i32, i32* %2
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_TIMESTAMP
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %3, i32 4)
%15 = load i32, i32* %2
store i32 %15, i32* %1
br label %16
16: ; preds = %10, %9
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@SOL_SOCKET = global i32 0
@SO_TIMESTAMP = global i32 0
define i32 @ping_open() {
%1 = alloca i32
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @IPPROTO_ICMP
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_TIMESTAMP
%11 = call i32 @setsockopt(i32 %5, i32 %9, i32 %10, i32* %1, i32 4)
br label %12
12: ; preds = %0, %7
%13 = phi i32 [ %5, %7 ], [ -1, %0 ]
ret i32 %13
}