#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *);
int querycns(int /*<<< orphan*/, int, int, int /*<<< orphan*/,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ showcns();
int cmd_poke(int argc, char **argv) {
  int r;
  alarm(1);
  if ((r = querycns(0, 0x0000, 0x01, 0, NULL))) {
    if (r > 0)
      showcns();
    else if (errno == EINTR)
      printf("No reply, must be dead\n");
    else
      err(9, "query failed");
    return -1;
  } else {
    printf("Alive and kicking\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<cmd_poke>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <alarm@plt>
xor    %ecx,%ecx
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    %ecx,%edi
mov    %ecx,%esi
call   1060 <querycns@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11ed <cmd_poke+0x9d>
cmpl   $0x0,-0x14(%rbp)
jle    11a0 <cmd_poke+0x50>
mov    $0x0,%al
call   1070 <showcns@plt>
jmp    11e1 <cmd_poke+0x91>
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jne    11cb <cmd_poke+0x7b>
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
jmp    11dc <cmd_poke+0x8c>
mov    $0x9,%edi
lea    0xe41(%rip),%rsi
call   1050 <err@plt>
jmp    11e1 <cmd_poke+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <cmd_poke+0xb0>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_poke>:
push   %rbx
mov    $0x1,%edi
call   1040 <alarm@plt>
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <querycns@plt>
test   %eax,%eax
je     117f <cmd_poke+0x2f>
jle    118d <cmd_poke+0x3d>
xor    %eax,%eax
call   1070 <showcns@plt>
jmp    11c2 <cmd_poke+0x72>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
jmp    11c7 <cmd_poke+0x77>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <cmd_poke+0x61>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <cmd_poke+0x72>
lea    0xe48(%rip),%rsi
mov    $0x9,%edi
call   1050 <err@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"No reply, must be dead\0A\00"
@.str.1 = [13 x i8] c"query failed\00"
@.str.2 = [19 x i8] c"Alive and kicking\0A\00"
define i32 @cmd_poke(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @alarm(i32 1)
%8 = call i32 @querycns(i32 0, i32 0, i32 1, i32 0, i32* null)
store i32 %8, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @showcns()
br label %24
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = call i32 @err(i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
br label %24
24: ; preds = %23, %13
store i32 -1, i32* %3
br label %27
25: ; preds = %2
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %27
27: ; preds = %25, %24
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [13 x i8] c"query failed\00"
@str = [18 x i8] c"Alive and kicking\00"
@str.3 = [23 x i8] c"No reply, must be dead\00"
define i32 @cmd_poke(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @alarm(i32 1)
%4 = tail call i32 @querycns(i32 0, i32 0, i32 1, i32 0, i32* null)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (...) @showcns()
br label %20
10: ; preds = %6
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0))
br label %20
16: ; preds = %10
%17 = tail call i32 @err(i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %8, %16, %14, %18
%21 = phi i32 [ 0, %18 ], [ -1, %14 ], [ -1, %16 ], [ -1, %8 ]
ret i32 %21
}