#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__ EINVAL;
scalar_t__ EPERM;
scalar_t__ ESRCH;
scalar_t__ errno;
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
void check(int pid) {
  int rc = kill(pid, 0);
  if (rc == 0) {
    printf("%d running\n", pid);
  } else if (errno == EINVAL) {
  } else if (errno == EPERM) {
    printf("%d noperm\n", pid);
  } else if (errno == ESRCH) {
  } else {
    printf("%d error %d\n", pid, errno);
  }
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <kill@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1158 <check+0x38>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <check+0xd0>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
jne    1177 <check+0x57>
jmp    11eb <check+0xcb>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jne    11a7 <check+0x87>
mov    -0x4(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e6 <check+0xc6>
mov    0x2e32(%rip),%rax
mov    (%rax),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    11c6 <check+0xa6>
jmp    11e1 <check+0xc1>
mov    -0x4(%rbp),%esi
mov    0x2e10(%rip),%rax
mov    (%rax),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e6 <check+0xc6>
jmp    11eb <check+0xcb>
jmp    11f0 <check+0xd0>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbx
mov    %edi,%ebx
xor    %esi,%esi
call   1040 <kill@plt>
test   %eax,%eax
je     1159 <check+0x39>
mov    0x2eab(%rip),%rax
mov    (%rax),%rdx
mov    0x2e99(%rip),%rax
cmp    (%rax),%rdx
je     1176 <check+0x56>
mov    0x2e7d(%rip),%rax
cmp    (%rax),%rdx
jne    116a <check+0x4a>
lea    0xeb5(%rip),%rdi
jmp    1160 <check+0x40>
lea    0xea0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
mov    0x2e4f(%rip),%rax
cmp    (%rax),%rdx
jne    1178 <check+0x58>
pop    %rbx
ret
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%d running\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@EPERM = global i64 0
@.str.1 = [11 x i8] c"%d noperm\0A\00"
@ESRCH = global i64 0
@.str.2 = [13 x i8] c"%d error %d\0A\00"
define void @check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @kill(i32 %4, i32 0)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %35
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINVAL
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %34
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EPERM
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %2
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %33
23: ; preds = %16
%24 = load i64, i64* @errno
%25 = load i64, i64* @ESRCH
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %32
28: ; preds = %23
%29 = load i32, i32* %2
%30 = load i64, i64* @errno
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %29, i64 %30)
br label %32
32: ; preds = %28, %27
br label %33
33: ; preds = %32, %20
br label %34
34: ; preds = %33, %15
br label %35
35: ; preds = %34, %8
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d running\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@EPERM = global i64 0
@.str.1 = [11 x i8] c"%d noperm\0A\00"
@ESRCH = global i64 0
@.str.2 = [13 x i8] c"%d error %d\0A\00"
define void @check(i32 %0) {
%2 = tail call i32 @kill(i32 %0, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %20
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINVAL
%9 = icmp eq i64 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = load i64, i64* @EPERM
%12 = icmp eq i64 %7, %11
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %20
15: ; preds = %10
%16 = load i64, i64* @ESRCH
%17 = icmp eq i64 %7, %16
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %0, i64 %7)
br label %20
20: ; preds = %6, %18, %15, %13, %4
ret void
}