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

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getopt(int, char **, char *);
int getpid();
int getppid();
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  int c;
  int pid = getpid();
  FILE *output = stdout;
  opterr = 0;
  while ((c = getopt(argc, argv, "spo:")) != -1) {
    switch (c) {
    case 'p':
      pid = getppid();
      break;
    case 's':
      pid = getpid();
      break;
    case 'o':
      output = fopen(optarg, "w");
      break;
    default:
      abort();
      break;
    }
  }
  fprintf(output, "%d\n", pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e43(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1239 <main+0xd9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6f,%eax
je     120f <main+0xaf>
jmp    11cf <main+0x6f>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
je     11f1 <main+0x91>
jmp    11e0 <main+0x80>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
je     1200 <main+0xa0>
jmp    122d <main+0xcd>
mov    $0x0,%al
call   1080 <getppid@plt>
mov    %eax,-0x18(%rbp)
jmp    1234 <main+0xd4>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x18(%rbp)
jmp    1234 <main+0xd4>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1234 <main+0xd4>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    119c <main+0x3c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdc0(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%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,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x4(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%rbx
mov    0x2e4c(%rip),%rax
movq   $0x0,(%rax)
lea    0xe66(%rip),%r14
mov    0x2e57(%rip),%r13
lea    0xe5d(%rip),%r12
jmp    11bf <main+0x5f>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x6f,%eax
je     11b0 <main+0x50>
cmp    $0xffffffff,%eax
je     11fa <main+0x9a>
cmp    $0x73,%eax
je     11ed <main+0x8d>
cmp    $0x70,%eax
jne    121e <main+0xbe>
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,0x4(%rsp)
jmp    11bf <main+0x5f>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x4(%rsp)
jmp    11bf <main+0x5f>
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
mov    0x4(%rsp),%edx
call   1050 <fprintf@plt>
xor    %eax,%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):
@stdout = global i32* null
@opterr = global i64 0
@.str = [5 x i8] c"spo:\00"
@optarg = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getpid()
store i32 %9, i32* %7
%10 = load i32*, i32** @stdout
store i32* %10, i32** %8
store i64 0, i64* @opterr
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %25 [
i32 112, label %18
i32 115, label %20
i32 111, label %22
]
18: ; preds = %16
%19 = call i32 (...) @getppid()
store i32 %19, i32* %7
br label %27
20: ; preds = %16
%21 = call i32 (...) @getpid()
store i32 %21, i32* %7
br label %27
22: ; preds = %16
%23 = load i32, i32* @optarg
%24 = call i32* @fopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %8
br label %27
25: ; preds = %16
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %22, %20, %18
br label %11
28: ; preds = %11
%29 = load i32*, i32** %8
%30 = load i32, i32* %7
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32* null
@opterr = global i64 0
@.str = [5 x i8] c"spo:\00"
@optarg = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @getpid()
%4 = load i32*, i32** @stdout
store i64 0, i64* @opterr
br label %5
5: ; preds = %15, %2
%6 = phi i32 [ %3, %2 ], [ %16, %15 ]
%7 = phi i32* [ %4, %2 ], [ %9, %15 ]
br label %8
8: ; preds = %5, %17
%9 = phi i32* [ %19, %17 ], [ %7, %5 ]
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %20 [
i32 -1, label %22
i32 112, label %11
i32 115, label %13
i32 111, label %17
]
11: ; preds = %8
%12 = tail call i32 (...) @getppid()
br label %15
13: ; preds = %8
%14 = tail call i32 (...) @getpid()
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
br label %5
17: ; preds = %8
%18 = load i32, i32* @optarg
%19 = tail call i32* @fopen(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %8
20: ; preds = %8
%21 = tail call i32 (...) @abort()
unreachable
22: ; preds = %8
%23 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
ret i32 0
}