#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 /*<<< orphan*/ addToFile(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
scalar_t__ optind;
char optopt;
int /*<<< orphan*/ removeFromFile(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  int list, add, remove;
  char c;
  add = remove = 0;
  optind = 0;
  while ((c = getopt(argc, argv, "la:r:")) != -1) {
    switch (c) {
    case 'l':
      list = 1;
      system("sort todo");
      break;
    case 'a':
      if (!remove) {
        add = 1;
        addToFile(optarg);
      }
      break;
    case 'r':
      if (!add) {
        remove = 1;
        removeFromFile(optarg);
      }
      break;
    case '?':
      if (optopt == 'a')
        fprintf(stderr, "Option a requiers parameter \n");
      else if (optopt == 'b')
        fprintf(stderr, "Option b requires parameter \n");
      break;
    }
  }
  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)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdx
call   1070 <getopt@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12b0 <main+0x160>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     124c <main+0xfc>
jmp    11b9 <main+0x69>
mov    -0x24(%rbp),%eax
sub    $0x61,%eax
je     1204 <main+0xb4>
jmp    11ca <main+0x7a>
mov    -0x24(%rbp),%eax
sub    $0x6c,%eax
je     11ec <main+0x9c>
jmp    11db <main+0x8b>
mov    -0x24(%rbp),%eax
sub    $0x72,%eax
je     1228 <main+0xd8>
jmp    12ab <main+0x15b>
movl   $0x1,-0x14(%rbp)
lea    0xe0c(%rip),%rdi
call   1040 <system@plt>
jmp    12ab <main+0x15b>
cmpl   $0x0,-0x1c(%rbp)
jne    1223 <main+0xd3>
movl   $0x1,-0x18(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1050 <addToFile@plt>
jmp    12ab <main+0x15b>
cmpl   $0x0,-0x18(%rbp)
jne    1247 <main+0xf7>
movl   $0x1,-0x1c(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1030 <removeFromFile@plt>
jmp    12ab <main+0x15b>
mov    0x2d8d(%rip),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jne    1279 <main+0x129>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12a6 <main+0x156>
mov    0x2d60(%rip),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    12a1 <main+0x151>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12a6 <main+0x156>
jmp    12ab <main+0x15b>
jmp    1182 <main+0x32>
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,%rbx
mov    %edi,%ebp
mov    0x2e71(%rip),%rax
movq   $0x0,(%rax)
lea    0xe8b(%rip),%rdx
call   1070 <getopt@plt>
cmp    $0xff,%al
je     127b <main+0x12b>
xor    %r15d,%r15d
lea    0xe74(%rip),%r12
lea    0xe73(%rip),%r13
xor    %r14d,%r14d
jmp    11c5 <main+0x75>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1060 <fprintf@plt>
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0xff,%al
je     127b <main+0x12b>
movsbl %al,%eax
cmp    $0x6b,%eax
jg     1200 <main+0xb0>
cmp    $0x3f,%eax
je     1220 <main+0xd0>
cmp    $0x61,%eax
jne    11b0 <main+0x60>
test   %r14d,%r14d
mov    $0x1,%r14d
jne    11b0 <main+0x60>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1050 <addToFile@plt>
mov    $0x1,%r15d
xor    %r14d,%r14d
jmp    11b0 <main+0x60>
nopl   0x0(%rax,%rax,1)
cmp    $0x72,%eax
je     1250 <main+0x100>
cmp    $0x6c,%eax
jne    11b0 <main+0x60>
mov    %r13,%rdi
call   1040 <system@plt>
jmp    11b0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2db9(%rip),%rax
movzbl (%rax),%eax
cmp    $0x62,%al
je     1198 <main+0x48>
cmp    $0x61,%al
jne    11b0 <main+0x60>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
jmp    11a8 <main+0x58>
nop
test   %r15d,%r15d
mov    $0x1,%r15d
jne    11b0 <main+0x60>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1030 <removeFromFile@plt>
xor    %r15d,%r15d
mov    $0x1,%r14d
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@optind = global i64 0
@.str = [6 x i8] c"la:r:\00"
@.str.1 = [10 x i8] c"sort todo\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Option a requiers parameter \0A\00"
@.str.3 = [30 x i8] c"Option b requires parameter \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
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %7
store i64 0, i64* @optind
br label %10
10: ; preds = %51, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call signext i8 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %13, i8* %9
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %52
16: ; preds = %10
%17 = load i8, i8* %9
%18 = sext i8 %17 to i32
switch i32 %18, label %51 [
i32 108, label %19
i32 97, label %21
i32 114, label %28
i32 63, label %35
]
19: ; preds = %16
store i32 1, i32* %6
%20 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %51
21: ; preds = %16
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
store i32 1, i32* %7
%25 = load i32, i32* @optarg
%26 = call i32 @addToFile(i32 %25)
br label %27
27: ; preds = %24, %21
br label %51
28: ; preds = %16
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
store i32 1, i32* %8
%32 = load i32, i32* @optarg
%33 = call i32 @removeFromFile(i32 %32)
br label %34
34: ; preds = %31, %28
br label %51
35: ; preds = %16
%36 = load i8, i8* @optopt
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 97
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %50
42: ; preds = %35
%43 = load i8, i8* @optopt
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 98
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %46, %42
br label %50
50: ; preds = %49, %39
br label %51
51: ; preds = %16, %50, %34, %27, %19
br label %10
52: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@optind = global i64 0
@.str = [6 x i8] c"la:r:\00"
@.str.1 = [10 x i8] c"sort todo\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Option a requiers parameter \0A\00"
@.str.3 = [30 x i8] c"Option b requires parameter \0A\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @optind
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %35, label %5
5: ; preds = %2, %30
%6 = phi i8 [ %33, %30 ], [ %3, %2 ]
%7 = phi i32 [ %32, %30 ], [ 0, %2 ]
%8 = phi i32 [ %31, %30 ], [ 0, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %30 [
i32 108, label %10
i32 97, label %12
i32 114, label %17
i32 63, label %22
]
10: ; preds = %5
%11 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %30
12: ; preds = %5
%13 = icmp eq i32 %8, 0
br i1 %13, label %14, label %30
14: ; preds = %12
%15 = load i32, i32* @optarg
%16 = tail call i32 @addToFile(i32 %15)
br label %30
17: ; preds = %5
%18 = icmp eq i32 %7, 0
br i1 %18, label %19, label %30
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = tail call i32 @removeFromFile(i32 %20)
br label %30
22: ; preds = %5
%23 = load i8, i8* @optopt
switch i8 %23, label %30 [
i8 97, label %24
i8 98, label %27
]
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %22, %24, %27, %17, %19, %12, %14, %5, %10
%31 = phi i32 [ %8, %5 ], [ %8, %24 ], [ %8, %27 ], [ %8, %17 ], [ 1, %19 ], [ 1, %12 ], [ 0, %14 ], [ %8, %10 ], [ %8, %22 ]
%32 = phi i32 [ %7, %5 ], [ %7, %24 ], [ %7, %27 ], [ 1, %17 ], [ 0, %19 ], [ %7, %12 ], [ 1, %14 ], [ %7, %10 ], [ %7, %22 ]
%33 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i8 %33, -1
br i1 %34, label %35, label %5
35: ; preds = %30, %2
ret i32 0
}