#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ ERANGE;
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fprintf_process(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
char optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
long strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  long pid = -1;
  int c;
  opterr = 0;
  while ((c = getopt(argc, argv, "hp:")) != -1) {
    switch (c) {
    case 'h':
      printf("Usage: %s -p <pid>\n", argv[0]);
      return 0;
      break;
    case 'p':
      pid = strtol(optarg, NULL, 10);
      if ((errno == ERANGE && (pid == LONG_MAX || pid == LONG_MIN)) ||
          (errno != 0 && pid == 0)) {
        perror("strtol");
        return 1;
      }
      if (pid < 0) {
        fprintf(stderr, "cannot accept negative pids\n");
        return 1;
      }
      break;
    case '?':
      if (optopt == 'p') {
        fprintf(stderr, "Option -p requires an argument.\n");
      } else if (isprint(optopt)) {
        fprintf(stderr, "Unknown option `-%c`.\n", optopt);
      } else {
        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
      }
      return 1;
      break;
    default:
      abort();
    }
  }
  if (pid == -1) {
    fprintf(stderr, "must specify a remote process with -p\n");
    return 1;
  }
  return fprintf_process((pid_t)pid);
}


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)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    0x2e03(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe46(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     138c <main+0x20c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x3f,%eax
je     12e1 <main+0x161>
jmp    11df <main+0x5f>
mov    -0x20(%rbp),%eax
sub    $0x68,%eax
je     1201 <main+0x81>
jmp    11f0 <main+0x70>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
je     1220 <main+0xa0>
jmp    1380 <main+0x200>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c8 <main+0x248>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
jne    127b <main+0xfb>
mov    -0x18(%rbp),%rax
mov    0x2d5a(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <main+0x116>
mov    -0x18(%rbp),%rax
mov    0x2d6e(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <main+0x116>
mov    0x2d2e(%rip),%rax
cmpl   $0x0,(%rax)
je     12ae <main+0x12e>
cmpq   $0x0,-0x18(%rbp)
jne    12ae <main+0x12e>
lea    0xd7b(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x248>
cmpq   $0x0,-0x18(%rbp)
jge    12dc <main+0x15c>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x248>
jmp    1387 <main+0x207>
mov    0x2cf0(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
jne    1310 <main+0x190>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1374 <main+0x1f4>
mov    0x2cc1(%rip),%rax
movsbl (%rax),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
je     134e <main+0x1ce>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
mov    0x2ca0(%rip),%rax
movsbl (%rax),%edx
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    136f <main+0x1ef>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
mov    0x2c7a(%rip),%rax
movsbl (%rax),%edx
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1374 <main+0x1f4>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x248>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11ac <main+0x2c>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    13ba <main+0x23a>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x248>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1080 <fprintf_process@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e11(%rip),%rax
movq   $0x0,(%rax)
mov    $0xffffffffffffffff,%rbx
lea    0xe54(%rip),%r15
mov    0x2dfd(%rip),%r13
mov    0x2e16(%rip),%r12
jmp    11c9 <main+0x49>
nopl   0x0(%rax)
test   %rbx,%rbx
js     1292 <main+0x112>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0x70,%eax
jne    122f <main+0xaf>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
mov    0x0(%r13),%eax
cmp    (%r12),%eax
jne    1215 <main+0x95>
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%rbx
je     121e <main+0x9e>
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rbx
je     121e <main+0x9e>
test   %eax,%eax
je     11c0 <main+0x40>
test   %rbx,%rbx
jne    11c0 <main+0x40>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
jmp    12ec <main+0x16c>
cmp    $0xffffffff,%eax
je     1258 <main+0xd8>
cmp    $0x3f,%eax
je     1273 <main+0xf3>
cmp    $0x68,%eax
jne    1300 <main+0x180>
mov    (%r14),%rsi
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    12f1 <main+0x171>
cmp    $0xffffffffffffffff,%rbx
je     12c5 <main+0x145>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf_process@plt>
mov    0x2d5e(%rip),%rbx
mov    (%rbx),%al
cmp    $0x70,%al
jne    12a4 <main+0x124>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
jmp    12d5 <main+0x155>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
jmp    12d5 <main+0x155>
movsbl %al,%edi
call   1070 <isprint@plt>
mov    0x2d0d(%rip),%rcx
mov    (%rcx),%edi
movsbl (%rbx),%edx
test   %eax,%eax
je     12de <main+0x15e>
lea    0xd9a(%rip),%rsi
jmp    12e5 <main+0x165>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12ec <main+0x16c>
lea    0xd8f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@opterr = global i64 0
@.str = [4 x i8] c"hp:\00"
@.str.1 = [20 x i8] c"Usage: %s -p <pid>\0A\00"
@optarg = global i32 0
@errno = global i32 0
@ERANGE = global i32 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.2 = [7 x i8] c"strtol\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"cannot accept negative pids\0A\00"
@optopt = global i8 0
@.str.4 = [33 x i8] c"Option -p requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown option `-%c`.\0A\00"
@.str.6 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@.str.7 = [39 x i8] c"must specify a remote process with -p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %6
store i64 0, i64* @opterr
br label %8
8: ; preds = %74, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %7
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %75
13: ; preds = %8
%14 = load i32, i32* %7
switch i32 %14, label %72 [
i32 104, label %15
i32 112, label %20
i32 63, label %49
]
15: ; preds = %13
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 0, i32* %3
br label %85
20: ; preds = %13
%21 = load i32, i32* @optarg
%22 = call i64 @strtol(i32 %21, i32* null, i32 10)
store i64 %22, i64* %6
%23 = load i32, i32* @errno
%24 = load i32, i32* @ERANGE
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i64, i64* %6
%28 = load i64, i64* @LONG_MAX
%29 = icmp eq i64 %27, %28
br i1 %29, label %40, label %30
30: ; preds = %26
%31 = load i64, i64* %6
%32 = load i64, i64* @LONG_MIN
%33 = icmp eq i64 %31, %32
br i1 %33, label %40, label %34
34: ; preds = %30, %20
%35 = load i32, i32* @errno
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i64, i64* %6
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37, %30, %26
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %85
42: ; preds = %37, %34
%43 = load i64, i64* %6
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %85
48: ; preds = %42
br label %74
49: ; preds = %13
%50 = load i8, i8* @optopt
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 112
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %71
56: ; preds = %49
%57 = load i8, i8* @optopt
%58 = call i32 @isprint(i8 signext %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i8, i8* @optopt
%63 = sext i8 %62 to i32
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %70
65: ; preds = %56
%66 = load i32, i32* @stderr
%67 = load i8, i8* @optopt
%68 = sext i8 %67 to i32
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %65, %60
br label %71
71: ; preds = %70, %53
store i32 1, i32* %3
br label %85
72: ; preds = %13
%73 = call i32 (...) @abort()
unreachable
74: ; preds = %48
br label %8
75: ; preds = %8
%76 = load i64, i64* %6
%77 = icmp eq i64 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %85
81: ; preds = %75
%82 = load i64, i64* %6
%83 = trunc i64 %82 to i32
%84 = call i32 @fprintf_process(i32 %83)
store i32 %84, i32* %3
br label %85
85: ; preds = %81, %78, %71, %45, %40, %15
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [4 x i8] c"hp:\00"
@.str.1 = [20 x i8] c"Usage: %s -p <pid>\0A\00"
@optarg = global i32 0
@errno = global i32 0
@ERANGE = global i32 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.2 = [7 x i8] c"strtol\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"cannot accept negative pids\0A\00"
@optopt = global i8 0
@.str.4 = [33 x i8] c"Option -p requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown option `-%c`.\0A\00"
@.str.6 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@.str.7 = [39 x i8] c"must specify a remote process with -p\0A\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %27, %2
%4 = phi i64 [ -1, %2 ], [ %11, %27 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %48 [
i32 -1, label %50
i32 104, label %6
i32 112, label %9
i32 63, label %32
]
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %58
9: ; preds = %3
%10 = load i32, i32* @optarg
%11 = tail call i64 @strtol(i32 %10, i32* null, i32 10)
%12 = load i32, i32* @errno
%13 = load i32, i32* @ERANGE
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i64, i64* @LONG_MAX
%17 = icmp eq i64 %11, %16
%18 = load i64, i64* @LONG_MIN
%19 = icmp eq i64 %11, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %25, label %21
21: ; preds = %15, %9
%22 = icmp ne i32 %12, 0
%23 = icmp eq i64 %11, 0
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %27
25: ; preds = %21, %15
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %58
27: ; preds = %21
%28 = icmp slt i64 %11, 0
br i1 %28, label %29, label %3
29: ; preds = %27
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %58
32: ; preds = %3
%33 = load i8, i8* @optopt
%34 = icmp eq i8 %33, 112
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %58
38: ; preds = %32
%39 = tail call i32 @isprint(i8 signext %33)
%40 = icmp eq i32 %39, 0
%41 = load i32, i32* @stderr
%42 = load i8, i8* @optopt
%43 = sext i8 %42 to i32
br i1 %40, label %46, label %44
44: ; preds = %38
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %58
46: ; preds = %38
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %58
48: ; preds = %3
%49 = tail call i32 (...) @abort()
unreachable
50: ; preds = %3
%51 = icmp eq i64 %4, -1
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %58
55: ; preds = %50
%56 = trunc i64 %4 to i32
%57 = tail call i32 @fprintf_process(i32 %56)
br label %58
58: ; preds = %35, %46, %44, %55, %52, %29, %25, %6
%59 = phi i32 [ 1, %25 ], [ 1, %29 ], [ 0, %6 ], [ 1, %52 ], [ %57, %55 ], [ 1, %44 ], [ 1, %46 ], [ 1, %35 ]
ret i32 %59
}