#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int is_host_alive(char *host_ip) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0) {
    return -1;
  } else if (pid == 0) {
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
    execlp("ping", "ping", "-c", "1", host_ip, NULL);
    exit(EXIT_FAILURE);
  }
  waitpid(pid, &status, 0);
  if (WIFEXITED(status))
    return WEXITSTATUS(status) == 0;
  return -1;
}


x86 assembly (clang, -O0):
<is_host_alive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    119d <is_host_alive+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <is_host_alive+0xd1>
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <is_host_alive+0x88>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%r8
lea    0xe31(%rip),%rsi
lea    0xe2f(%rip),%rdx
lea    0xe2b(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11fd <is_host_alive+0x8d>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     123a <is_host_alive+0xca>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1241 <is_host_alive+0xd1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_host_alive>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     11b8 <is_host_alive+0x48>
je     11c1 <is_host_alive+0x51>
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     11b8 <is_host_alive+0x48>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
lea    0xe1c(%rip),%rdi
lea    0xe1a(%rip),%rdx
lea    0xe16(%rip),%rcx
mov    %rdi,%rsi
mov    %rbx,%r8
xor    %r9d,%r9d
call   1080 <execlp@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [5 x i8] c"ping\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [2 x i8] c"1\00"
@EXIT_FAILURE = global i32 0
define i32 @is_host_alive(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %34
9: ; preds = %1
%10 = load i64, i64* %4
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* @STDERR_FILENO
%16 = call i32 @close(i32 %15)
%17 = load i8*, i8** %3
%18 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32* null)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %9
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = call i32 @waitpid(i64 %23, i32* %5, i32 0)
%25 = load i32, i32* %5
%26 = call i64 @WIFEXITED(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* %5
%30 = call i64 @WEXITSTATUS(i32 %29)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
store i32 %32, i32* %2
br label %34
33: ; preds = %22
store i32 -1, i32* %2
br label %34
34: ; preds = %33, %28, %8
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [5 x i8] c"ping\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [2 x i8] c"1\00"
@EXIT_FAILURE = global i32 0
define i32 @is_host_alive(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %1
%7 = icmp eq i64 %4, 0
br i1 %7, label %8, label %16
8: ; preds = %6
%9 = load i32, i32* @STDOUT_FILENO
%10 = tail call i32 @close(i32 %9)
%11 = load i32, i32* @STDERR_FILENO
%12 = tail call i32 @close(i32 %11)
%13 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %6
%17 = call i32 @waitpid(i64 %4, i32* %2, i32 0)
%18 = load i32, i32* %2
%19 = call i64 @WIFEXITED(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i64 @WEXITSTATUS(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %16, %1, %21
%27 = phi i32 [ %25, %21 ], [ -1, %1 ], [ -1, %16 ]
ret i32 %27
}