#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*/ result;
typedef int /*<<< orphan*/ options;
typedef int /*<<< orphan*/ command;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int cpoke(const char addy[]) {
  char *command = "ping \0";
  char *options = " -c 1 | grep -E -o '[0-9]+ received' | cut -f1 -d' '\0";
  int nums = sizeof(command) + sizeof(&addy) + sizeof(options);
  char fullcommand[nums];
  FILE *theCmdF;
  strcpy(fullcommand, command);
  strcat(fullcommand, addy);
  strcat(fullcommand, options);
  char result[5];
  theCmdF = popen(fullcommand, "r");
  fgets(result, sizeof(result) - 1, theCmdF);
  if (atoi(result) == 0) {
    return 1;
  } else if (atoi(result) == 1) {
    return 0;
  }
}


x86 assembly (clang, -O0):
<cpoke>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x18,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x58(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x40(%rbp)
lea    -0x45(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x4,%esi
call   1040 <fgets@plt>
lea    -0x45(%rbp),%rdi
call   1060 <atoi@plt>
cmp    $0x0,%eax
jne    120d <cpoke+0xbd>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    123e <cpoke+0xee>
lea    -0x45(%rbp),%rdi
call   1060 <atoi@plt>
cmp    $0x1,%eax
jne    1232 <cpoke+0xe2>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    123e <cpoke+0xee>
jmp    1237 <cpoke+0xe7>
movl   $0x0,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpoke>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ping \00\00"
@.str.1 = [54 x i8] c" -c 1 | grep -E -o '[0-9]+ received' | cut -f1 -d' '\00\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @cpoke(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca [5 x i8]
%11 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i32 24, i32* %6
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %15, i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @strcat(i8* %15, i8* %20)
%22 = call i32* @popen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %9
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%24 = load i32*, i32** %9
%25 = call i32 @fgets(i8* %23, i32 4, i32* %24)
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%27 = call i32 @atoi(i8* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %1
store i32 1, i32* %2
store i32 1, i32* %11
br label %37
30: ; preds = %1
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%32 = call i32 @atoi(i8* %31)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %2
store i32 1, i32* %11
br label %37
35: ; preds = %30
br label %36
36: ; preds = %35
store i32 0, i32* %11
br label %37
37: ; preds = %36, %34, %29
%38 = load i8*, i8** %7
%39 = load i32, i32* %11
switch i32 %39, label %42 [
i32 0, label %40
i32 1, label %40
]
40: ; preds = %37, %37
%41 = load i32, i32* %2
ret i32 %41
42: ; preds = %37
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"ping \00\00"
@.str.1 = [54 x i8] c" -c 1 | grep -E -o '[0-9]+ received' | cut -f1 -d' '\00\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @cpoke(i8* %0) {
%2 = alloca [5 x i8]
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcat(i8* %4, i8* %0)
%7 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%9 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @fgets(i8* %8, i32 4, i32* %9)
%11 = call i32 @atoi(i8* %8)
%12 = icmp ne i32 %11, 1
%13 = zext i1 %12 to i32
ret i32 %13
}