#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 */
int atoi(char *);
int /*<<< orphan*/ check(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ probe(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "usage: proccheck PID\n");
    exit(1);
  }
  int pid = atoi(argv[1]);
  if (pid == 0) {
    for (pid = 1; pid < 65536; ++pid) {
      check(pid);
    }
  } else {
    printf("%s\n", probe(pid) ? "proc" : "noproc");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e8 <main+0x88>
movl   $0x1,-0x14(%rbp)
cmpl   $0x10000,-0x14(%rbp)
jge    11e3 <main+0x83>
mov    -0x14(%rbp),%edi
call   1060 <check@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <main+0x60>
jmp    1215 <main+0xb5>
mov    -0x14(%rbp),%edi
call   1030 <probe@plt>
mov    %rax,%rcx
lea    0xe20(%rip),%rsi
lea    0xe1b(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11c6 <main+0x66>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     119d <main+0x3d>
mov    %eax,%edi
call   1030 <probe@plt>
test   %rax,%rax
lea    0xe96(%rip),%rax
lea    0xe91(%rip),%rsi
cmove  %rax,%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
jmp    11c2 <main+0x62>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1060 <check@plt>
add    $0x1,%ebx
cmp    $0x10000,%ebx
jne    11b0 <main+0x50>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: proccheck PID\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [7 x i8] c"noproc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %13
store i32 1, i32* %6
br label %21
21: ; preds = %27, %20
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 65536
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* %6
%26 = call i32 @check(i32 %25)
br label %27
27: ; preds = %24
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %21
30: ; preds = %21
br label %38
31: ; preds = %13
%32 = load i32, i32* %6
%33 = call i64 @probe(i32 %32)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %31, %30
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: proccheck PID\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"proc\00"
@.str.3 = [7 x i8] c"noproc\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8, %13
%14 = phi i32 [ %16, %13 ], [ 1, %8 ]
%15 = tail call i32 @check(i32 %14)
%16 = add nuw nsw i32 %14, 1
%17 = icmp eq i32 %16, 65536
br i1 %17, label %23, label %13
18: ; preds = %8
%19 = tail call i64 @probe(i32 %11)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %13, %18
ret i32 0
}