#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ *member_2;
  int /*<<< orphan*/ const member_1;
};

/* Variables and functions */
int /*<<< orphan*/ add_todo(int /*<<< orphan*/);
int getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ help();
int /*<<< orphan*/ list_all();
int /*<<< orphan*/ list_id(int /*<<< orphan*/);
#define no_argument 129
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ remove_todo(int /*<<< orphan*/);
#define required_argument 128
int /*<<< orphan*/ search(int /*<<< orphan*/);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int c;
  unsigned int iseed = (unsigned int)time(NULL);
  srand(iseed);
  if (argc == 1) {
    list_all();
    return 0;
  }
  while (1) {
    static struct option long_options[] = {
        {"help", no_argument, NULL, 'h'},
        {"add", required_argument, NULL, 'a'},
        {"show", required_argument, NULL, 's'},
        {"done", required_argument, NULL, 'd'},
        {"list", required_argument, NULL, 'l'},
        {0, 0, 0, 0}};
    int option_index = 0;
    c = getopt_long(argc, argv, "ha:s:d:l:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 'h':
      help();
      break;
    case 'a':
      add_todo(optarg);
      break;
    case 's':
      list_id(optarg);
      break;
    case 'd':
      remove_todo(optarg);
      break;
    case 'l':
      search(optarg);
      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)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <srand@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11d7 <main+0x47>
mov    $0x0,%al
call   10a0 <list_all@plt>
movl   $0x0,-0x4(%rbp)
jmp    129b <main+0x10b>
jmp    11dc <main+0x4c>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdx
lea    0x2e78(%rip),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1213 <main+0x83>
jmp    1294 <main+0x104>
mov    -0x14(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x12,%eax
ja     128f <main+0xff>
mov    -0x28(%rbp),%rax
lea    0xdcd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10b0 <help@plt>
jmp    128f <main+0xff>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1050 <add_todo@plt>
jmp    128f <main+0xff>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1090 <list_id@plt>
jmp    128f <main+0xff>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1070 <remove_todo@plt>
jmp    128f <main+0xff>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1040 <search@plt>
jmp    11dc <main+0x4c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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,%r13
mov    %edi,%ebp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    $0x1,%ebp
jne    11bf <main+0x2f>
xor    %eax,%eax
call   10a0 <list_all@plt>
jmp    125a <main+0xca>
lea    0xe9e(%rip),%r14
lea    0x2ea3(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe27(%rip),%rbx
jmp    11f0 <main+0x60>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1040 <search@plt>
nopl   0x0(%rax)
movl   $0x0,0x4(%rsp)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1030 <getopt_long@plt>
lea    -0x61(%rax),%ecx
cmp    $0x12,%ecx
ja     1255 <main+0xc5>
movslq (%rbx,%rcx,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1050 <add_todo@plt>
jmp    11f0 <main+0x60>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1070 <remove_todo@plt>
jmp    11f0 <main+0x60>
xor    %eax,%eax
call   10b0 <help@plt>
jmp    11f0 <main+0x60>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <list_id@plt>
jmp    11f0 <main+0x60>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_options = internal global [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -127, i32* null, i32 104 }, %struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 97 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 -128, i32* null, i32 115 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 -128, i32* null, i32 100 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8 -128, i32* null, i32 108 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [5 x i8] c"show\00"
@.str.3 = [5 x i8] c"done\00"
@.str.4 = [5 x i8] c"list\00"
@.str.5 = [10 x i8] c"ha:s:d:l:\00"
@optarg = global i32 0
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 i64 @time(i32* null)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i32 @srand(i32 %11)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @list_all()
store i32 0, i32* %3
br label %43
17: ; preds = %2
br label %18
18: ; preds = %17, %41
store i32 0, i32* %8
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt_long(i32 %19, i8** %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %struct.option* getelementptr inbounds ([6 x %struct.option], [6 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %8)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %18
br label %42
25: ; preds = %18
%26 = load i32, i32* %6
switch i32 %26, label %41 [
i32 104, label %27
i32 97, label %29
i32 115, label %32
i32 100, label %35
i32 108, label %38
]
27: ; preds = %25
%28 = call i32 (...) @help()
br label %41
29: ; preds = %25
%30 = load i32, i32* @optarg
%31 = call i32 @add_todo(i32 %30)
br label %41
32: ; preds = %25
%33 = load i32, i32* @optarg
%34 = call i32 @list_id(i32 %33)
br label %41
35: ; preds = %25
%36 = load i32, i32* @optarg
%37 = call i32 @remove_todo(i32 %36)
br label %41
38: ; preds = %25
%39 = load i32, i32* @optarg
%40 = call i32 @search(i32 %39)
br label %41
41: ; preds = %25, %38, %35, %32, %29, %27
br label %18
42: ; preds = %24
store i32 0, i32* %3
br label %43
43: ; preds = %42, %15
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_options = internal global [6 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -127, i32* null, i32 104 }, %struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 97 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 -128, i32* null, i32 115 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 -128, i32* null, i32 100 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8 -128, i32* null, i32 108 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [5 x i8] c"show\00"
@.str.3 = [5 x i8] c"done\00"
@.str.4 = [5 x i8] c"list\00"
@.str.5 = [10 x i8] c"ha:s:d:l:\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i64 @time(i32* null)
%5 = trunc i64 %4 to i32
%6 = tail call i32 @srand(i32 %5)
%7 = icmp eq i32 %0, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
br label %12
10: ; preds = %2
%11 = tail call i32 (...) @list_all()
br label %30
12: ; preds = %8, %29
store i32 0, i32* %3
%13 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %struct.option* getelementptr inbounds ([6 x %struct.option], [6 x %struct.option]* @main.long_options, i64 0, i64 0), i32* %3)
switch i32 %13, label %29 [
i32 -1, label %14
i32 104, label %15
i32 97, label %17
i32 115, label %20
i32 100, label %23
i32 108, label %26
]
14: ; preds = %12
br label %30
15: ; preds = %12
%16 = call i32 (...) @help()
br label %29
17: ; preds = %12
%18 = load i32, i32* @optarg
%19 = call i32 @add_todo(i32 %18)
br label %29
20: ; preds = %12
%21 = load i32, i32* @optarg
%22 = call i32 @list_id(i32 %21)
br label %29
23: ; preds = %12
%24 = load i32, i32* @optarg
%25 = call i32 @remove_todo(i32 %24)
br label %29
26: ; preds = %12
%27 = load i32, i32* @optarg
%28 = call i32 @search(i32 %27)
br label %29
29: ; preds = %15, %17, %20, %23, %26, %12
br label %12
30: ; preds = %14, %10
ret i32 0
}