#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 *);
scalar_t__ db_check_value(int);
int /*<<< orphan*/ db_delete(int);
int /*<<< orphan*/ db_read(int);
int db_write(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_random();
char *get_user_input();
int getopt(int, char **, char *);
scalar_t__ malloc(int);
int optind;
int /*<<< orphan*/ p_init();
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, size_t);
int /*<<< orphan*/ stderr;
char *str_trim(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  int id = 0;
  int opt = 0;
  int dflag = 0;
  int nflag = 0;
  int lflag = 0;
  int aflag = 0;
  extern char *optarg;
  p_init();
  while ((opt = getopt(argc, argv, "ad:n:hl")) != -1) {
    switch (opt) {
    case 'd':
      dflag = 1;
      id = atoi(optarg);
      break;
    case 'n':
      nflag = 1;
      id = atoi(optarg);
      break;
    case 'l':
      lflag = 1;
      break;
    case 'a':
      aflag = 1;
      break;
    case 'h':
    case '?':
      print_usage();
    }
  }
  if (nflag == 1) {
    if (db_check_value(id) != 0) {
      fprintf(stderr,
              "There is no such value in db! Look all entry list by -l key\n");
      return 37;
    } else {
      db_read(id);
    }
  } else if (dflag == 1) {
    if (db_check_value(id) != 0) {
      fprintf(stderr,
              "There is no such value in db! Look all entry list by -l key\n");
      return 37;
    } else {
      db_delete(id);
    }
  } else if (aflag == 1) {
    char *text = (char *)malloc(1024);
    if (optind < argc) {
      size_t s_length = 1;
      while (optind < argc) {
        s_length += strlen(argv[optind]) + 1;
        text = realloc(text, s_length);
        strcat(text, argv[optind]);
        strcat(text, " ");
        optind++;
      }
      text = str_trim(text);
    } else {
      printf("Enter string below [ctrl + d] to end input\n");
      text = get_user_input();
    }
    if (strlen(text) > 10) {
      int ecode = db_write(text);
      if (ecode != 0) {
        fprintf(stderr, "Error write to db \"%s\"\n", text);
        free(text);
        return ecode;
      } else {
        printf("\"%s\"\n%d symbol(s) writed to db succeful!\n", text,
               strlen(text));
        free(text);
        return 0;
      }
    } else {
      printf("Too short string. Skiped...\n");
      free(text);
      return 0;
    }
  } else if (lflag == 1) {
    db_read(0);
  } else {
    get_random();
  }
  free(optarg);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   10c0 <p_init@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdx
call   1100 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     130f <main+0xef>
mov    -0x18(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x2f,%eax
ja     130a <main+0xea>
mov    -0x48(%rbp),%rax
lea    0xd5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x1c(%rbp)
mov    0x2d1b(%rip),%rax
mov    (%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    130a <main+0xea>
movl   $0x1,-0x20(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    130a <main+0xea>
movl   $0x1,-0x24(%rbp)
jmp    130a <main+0xea>
movl   $0x1,-0x28(%rbp)
jmp    130a <main+0xea>
mov    $0x0,%al
call   1130 <print_usage@plt>
jmp    1267 <main+0x47>
cmpl   $0x1,-0x20(%rbp)
jne    135b <main+0x13b>
mov    -0x14(%rbp),%edi
call   10f0 <db_check_value@plt>
cmp    $0x0,%rax
je     134e <main+0x12e>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x25,-0x4(%rbp)
jmp    1586 <main+0x366>
mov    -0x14(%rbp),%edi
call   10e0 <db_read@plt>
jmp    1570 <main+0x350>
cmpl   $0x1,-0x1c(%rbp)
jne    13a7 <main+0x187>
mov    -0x14(%rbp),%edi
call   10f0 <db_check_value@plt>
cmp    $0x0,%rax
je     139a <main+0x17a>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x25,-0x4(%rbp)
jmp    1586 <main+0x366>
mov    -0x14(%rbp),%edi
call   1090 <db_delete@plt>
jmp    156b <main+0x34b>
cmpl   $0x1,-0x28(%rbp)
jne    1544 <main+0x324>
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1477 <main+0x257>
movq   $0x1,-0x38(%rbp)
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1465 <main+0x245>
mov    -0x10(%rbp),%rax
mov    0x2bf2(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10d0 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2bb9(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
call   1120 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xcbf(%rip),%rsi
call   1120 <strcat@plt>
mov    0x2b96(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2b8a(%rip),%rax
mov    %ecx,(%rax)
jmp    13d9 <main+0x1b9>
mov    -0x30(%rbp),%rdi
call   1140 <str_trim@plt>
mov    %rax,-0x30(%rbp)
jmp    1490 <main+0x270>
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1030 <get_user_input@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0xa,%eax
jle    1521 <main+0x301>
mov    -0x30(%rbp),%rdi
call   1080 <db_write@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     14e7 <main+0x2c7>
mov    0x2b11(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1586 <main+0x366>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xc46(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1586 <main+0x366>
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1586 <main+0x366>
cmpl   $0x1,-0x24(%rbp)
jne    155a <main+0x33a>
xor    %edi,%edi
call   10e0 <db_read@plt>
jmp    1561 <main+0x341>
mov    $0x0,%al
call   1050 <get_random@plt>
jmp    1566 <main+0x346>
jmp    156b <main+0x34b>
jmp    1570 <main+0x350>
mov    0x2a61(%rip),%rax
mov    (%rax),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10d0 <p_init@plt>
lea    0xe6f(%rip),%r15
lea    0xda8(%rip),%r13
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r14d,%r14d
xor    %r12d,%r12d
movl   $0x0,0x10(%rsp)
jmp    1280 <main+0x50>
cmp    $0xffffffff,%eax
je     12f0 <main+0xc0>
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1110 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x2f,%ecx
ja     1278 <main+0x48>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
xor    %eax,%eax
call   1140 <print_usage@plt>
jmp    1280 <main+0x50>
movl   $0x1,0x10(%rsp)
jmp    1280 <main+0x50>
mov    0x2d1f(%rip),%rax
mov    (%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,%r14d
mov    $0x1,%al
mov    %eax,0x14(%rsp)
jmp    1280 <main+0x50>
movl   $0x1,0xc(%rsp)
jmp    1280 <main+0x50>
mov    0x2cfb(%rip),%rax
mov    (%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,%r14d
mov    $0x1,%r12d
jmp    1280 <main+0x50>
cmp    $0x1,%r12d
jne    1310 <main+0xe0>
mov    %r14d,%edi
call   1100 <db_check_value@plt>
test   %rax,%rax
jne    1328 <main+0xf8>
mov    %r14d,%edi
call   10f0 <db_read@plt>
jmp    1454 <main+0x224>
testb  $0x1,0x14(%rsp)
je     1349 <main+0x119>
mov    %r14d,%edi
call   1100 <db_check_value@plt>
test   %rax,%rax
je     13f6 <main+0x1c6>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x25,%ebp
jmp    1465 <main+0x235>
cmpl   $0x1,0x10(%rsp)
jne    13e6 <main+0x1b6>
mov    $0x400,%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    0x2c80(%rip),%r13
mov    0x0(%r13),%eax
cmp    %ebp,%eax
jge    1400 <main+0x1d0>
mov    $0x1,%r15d
lea    0xd84(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cltq
mov    (%rbx,%rax,8),%rdi
call   1070 <strlen@plt>
cltq
add    %rax,%r15
add    $0x1,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   10e0 <realloc@plt>
mov    %rax,%r14
movslq 0x0(%r13),%rax
mov    (%rbx,%rax,8),%rsi
mov    %r14,%rdi
call   1130 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1130 <strcat@plt>
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %eax,0x0(%r13)
cmp    %ebp,%eax
jl     1390 <main+0x160>
mov    %r14,%rdi
call   1150 <str_trim@plt>
jmp    1413 <main+0x1e3>
cmpl   $0x1,0xc(%rsp)
jne    144d <main+0x21d>
xor    %edi,%edi
call   10f0 <db_read@plt>
jmp    1454 <main+0x224>
mov    %r14d,%edi
call   10a0 <db_delete@plt>
jmp    1454 <main+0x224>
lea    0xd42(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <get_user_input@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <strlen@plt>
cmp    $0xb,%eax
jl     1476 <main+0x246>
mov    %rbx,%rdi
call   1090 <db_write@plt>
test   %eax,%eax
je     1487 <main+0x257>
mov    %eax,%ebp
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
lea    0xcc6(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14a4 <main+0x274>
xor    %eax,%eax
call   1060 <get_random@plt>
mov    0x2b7d(%rip),%rax
mov    (%rax),%rdi
call   1040 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf7(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
jmp    145e <main+0x22e>
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0xc89(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    1465 <main+0x235>

LLVM IR (-O0):
@.str = [8 x i8] c"ad:n:hl\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [61 x i8] c"There is no such value in db! Look all entry list by -l key\0A\00"
@optind = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [44 x i8] c"Enter string below [ctrl + d] to end input\0A\00"
@.str.4 = [24 x i8] c"Error write to db \22%s\22\0A\00"
@.str.5 = [42 x i8] c"\22%s\22\0A%d symbol(s) writed to db succeful!\0A\00"
@.str.6 = [29 x i8] c"Too short string. Skiped...\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%15 = call i32 (...) @p_init()
br label %16
16: ; preds = %33, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %7
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = load i32, i32* %7
switch i32 %22, label %33 [
i32 100, label %23
i32 110, label %26
i32 108, label %29
i32 97, label %30
i32 104, label %31
i32 63, label %31
]
23: ; preds = %21
store i32 1, i32* %8
%24 = load i8*, i8** @optarg
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
br label %33
26: ; preds = %21
store i32 1, i32* %9
%27 = load i8*, i8** @optarg
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %6
br label %33
29: ; preds = %21
store i32 1, i32* %10
br label %33
30: ; preds = %21
store i32 1, i32* %11
br label %33
31: ; preds = %21, %21
%32 = call i32 (...) @print_usage()
br label %33
33: ; preds = %31, %21, %30, %29, %26, %23
br label %16
34: ; preds = %16
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load i32, i32* %6
%39 = call i64 @db_check_value(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
store i32 37, i32* %3
br label %147
44: ; preds = %37
%45 = load i32, i32* %6
%46 = call i32 @db_read(i32 %45)
br label %47
47: ; preds = %44
br label %144
48: ; preds = %34
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %62
51: ; preds = %48
%52 = load i32, i32* %6
%53 = call i64 @db_check_value(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
store i32 37, i32* %3
br label %147
58: ; preds = %51
%59 = load i32, i32* %6
%60 = call i32 @db_delete(i32 %59)
br label %61
61: ; preds = %58
br label %143
62: ; preds = %48
%63 = load i32, i32* %11
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %134
65: ; preds = %62
%66 = call i64 @malloc(i32 1024)
%67 = inttoptr i64 %66 to i8*
store i8* %67, i8** %12
%68 = load i32, i32* @optind
%69 = load i32, i32* %4
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %104
71: ; preds = %65
store i64 1, i64* %13
br label %72
72: ; preds = %76, %71
%73 = load i32, i32* @optind
%74 = load i32, i32* %4
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %101
76: ; preds = %72
%77 = load i8**, i8*** %5
%78 = load i32, i32* @optind
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = call i32 @strlen(i8* %81)
%83 = add nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = load i64, i64* %13
%86 = add i64 %85, %84
store i64 %86, i64* %13
%87 = load i8*, i8** %12
%88 = load i64, i64* %13
%89 = call i8* @realloc(i8* %87, i64 %88)
store i8* %89, i8** %12
%90 = load i8*, i8** %12
%91 = load i8**, i8*** %5
%92 = load i32, i32* @optind
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 @strcat(i8* %90, i8* %95)
%97 = load i8*, i8** %12
%98 = call i32 @strcat(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%99 = load i32, i32* @optind
%100 = add nsw i32 %99, 1
store i32 %100, i32* @optind
br label %72
101: ; preds = %72
%102 = load i8*, i8** %12
%103 = call i8* @str_trim(i8* %102)
store i8* %103, i8** %12
br label %107
104: ; preds = %65
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%106 = call i8* (...) @get_user_input()
store i8* %106, i8** %12
br label %107
107: ; preds = %104, %101
%108 = load i8*, i8** %12
%109 = call i32 @strlen(i8* %108)
%110 = icmp sgt i32 %109, 10
br i1 %110, label %111, label %130
111: ; preds = %107
%112 = load i8*, i8** %12
%113 = call i32 @db_write(i8* %112)
store i32 %113, i32* %14
%114 = load i32, i32* %14
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %123
116: ; preds = %111
%117 = load i32, i32* @stderr
%118 = load i8*, i8** %12
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %118)
%120 = load i8*, i8** %12
%121 = call i32 @free(i8* %120)
%122 = load i32, i32* %14
store i32 %122, i32* %3
br label %147
123: ; preds = %111
%124 = load i8*, i8** %12
%125 = load i8*, i8** %12
%126 = call i32 @strlen(i8* %125)
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %124, i32 %126)
%128 = load i8*, i8** %12
%129 = call i32 @free(i8* %128)
store i32 0, i32* %3
br label %147
130: ; preds = %107
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%132 = load i8*, i8** %12
%133 = call i32 @free(i8* %132)
store i32 0, i32* %3
br label %147
134: ; preds = %62
%135 = load i32, i32* %10
%136 = icmp eq i32 %135, 1
br i1 %136, label %137, label %139
137: ; preds = %134
%138 = call i32 @db_read(i32 0)
br label %141
139: ; preds = %134
%140 = call i32 (...) @get_random()
br label %141
141: ; preds = %139, %137
br label %142
142: ; preds = %141
br label %143
143: ; preds = %142, %61
br label %144
144: ; preds = %143, %47
%145 = load i8*, i8** @optarg
%146 = call i32 @free(i8* %145)
store i32 0, i32* %3
br label %147
147: ; preds = %144, %130, %123, %116, %55, %41
%148 = load i32, i32* %3
ret i32 %148
}

LLVM IR (-O2):
@.str = [8 x i8] c"ad:n:hl\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [61 x i8] c"There is no such value in db! Look all entry list by -l key\0A\00"
@optind = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.4 = [24 x i8] c"Error write to db \22%s\22\0A\00"
@.str.5 = [42 x i8] c"\22%s\22\0A%d symbol(s) writed to db succeful!\0A\00"
@str = [43 x i8] c"Enter string below [ctrl + d] to end input\00"
@str.7 = [28 x i8] c"Too short string. Skiped...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @p_init()
br label %4
4: ; preds = %2, %23
%5 = phi i32 [ 0, %2 ], [ %25, %23 ]
%6 = phi i1 [ false, %2 ], [ true, %23 ]
%7 = phi i32 [ 0, %2 ], [ %12, %23 ]
%8 = phi i32 [ 0, %2 ], [ %16, %23 ]
%9 = phi i32 [ 0, %2 ], [ %19, %23 ]
br label %10
10: ; preds = %4, %26
%11 = phi i32 [ %28, %26 ], [ %5, %4 ]
%12 = phi i32 [ 1, %26 ], [ %7, %4 ]
%13 = phi i32 [ %16, %26 ], [ %8, %4 ]
%14 = phi i32 [ %19, %26 ], [ %9, %4 ]
br label %15
15: ; preds = %20, %10
%16 = phi i32 [ %13, %10 ], [ 1, %20 ]
%17 = phi i32 [ %14, %10 ], [ %19, %20 ]
br label %18
18: ; preds = %20, %15
%19 = phi i32 [ %17, %15 ], [ 1, %20 ]
br label %20
20: ; preds = %22, %18
%21 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %21, label %22 [
i32 -1, label %31
i32 100, label %23
i32 110, label %26
i32 108, label %15
i32 97, label %18
i32 104, label %29
i32 63, label %29
]
22: ; preds = %20, %29
br label %20
23: ; preds = %20
%24 = load i8*, i8** @optarg
%25 = tail call i32 @atoi(i8* %24)
br label %4
26: ; preds = %20
%27 = load i8*, i8** @optarg
%28 = tail call i32 @atoi(i8* %27)
br label %10
29: ; preds = %20, %20
%30 = tail call i32 (...) @print_usage()
br label %22
31: ; preds = %20
%32 = icmp eq i32 %12, 1
br i1 %32, label %33, label %41
33: ; preds = %31
%34 = tail call i64 @db_check_value(i32 %11)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %111
39: ; preds = %33
%40 = tail call i32 @db_read(i32 %11)
br label %108
41: ; preds = %31
br i1 %6, label %42, label %50
42: ; preds = %41
%43 = tail call i64 @db_check_value(i32 %11)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %111
48: ; preds = %42
%49 = tail call i32 @db_delete(i32 %11)
br label %108
50: ; preds = %41
%51 = icmp eq i32 %19, 1
br i1 %51, label %52, label %102
52: ; preds = %50
%53 = tail call i64 @malloc(i32 1024)
%54 = load i32, i32* @optind
%55 = icmp slt i32 %54, %0
br i1 %55, label %56, label %81
56: ; preds = %52
%57 = inttoptr i64 %53 to i8*
br label %58
58: ; preds = %56, %58
%59 = phi i32 [ %77, %58 ], [ %54, %56 ]
%60 = phi i64 [ %68, %58 ], [ 1, %56 ]
%61 = phi i8* [ %69, %58 ], [ %57, %56 ]
%62 = sext i32 %59 to i64
%63 = getelementptr inbounds i8*, i8** %1, i64 %62
%64 = load i8*, i8** %63
%65 = tail call i32 @strlen(i8* %64)
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = add i64 %60, %67
%69 = tail call i8* @realloc(i8* %61, i64 %68)
%70 = load i32, i32* @optind
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %1, i64 %71
%73 = load i8*, i8** %72
%74 = tail call i32 @strcat(i8* %69, i8* %73)
%75 = tail call i32 @strcat(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* @optind
%77 = add nsw i32 %76, 1
store i32 %77, i32* @optind
%78 = icmp slt i32 %77, %0
br i1 %78, label %58, label %79
79: ; preds = %58
%80 = tail call i8* @str_trim(i8* %69)
br label %84
81: ; preds = %52
%82 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%83 = tail call i8* (...) @get_user_input()
br label %84
84: ; preds = %81, %79
%85 = phi i8* [ %80, %79 ], [ %83, %81 ]
%86 = tail call i32 @strlen(i8* %85)
%87 = icmp sgt i32 %86, 10
br i1 %87, label %88, label %99
88: ; preds = %84
%89 = tail call i32 @db_write(i8* %85)
%90 = icmp eq i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %88
%92 = load i32, i32* @stderr
%93 = tail call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %85)
%94 = tail call i32 @free(i8* %85)
br label %111
95: ; preds = %88
%96 = tail call i32 @strlen(i8* %85)
%97 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %85, i32 %96)
%98 = tail call i32 @free(i8* %85)
br label %111
99: ; preds = %84
%100 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
%101 = tail call i32 @free(i8* %85)
br label %111
102: ; preds = %50
%103 = icmp eq i32 %16, 1
br i1 %103, label %104, label %106
104: ; preds = %102
%105 = tail call i32 @db_read(i32 0)
br label %108
106: ; preds = %102
%107 = tail call i32 (...) @get_random()
br label %108
108: ; preds = %48, %104, %106, %39
%109 = load i8*, i8** @optarg
%110 = tail call i32 @free(i8* %109)
br label %111
111: ; preds = %99, %95, %91, %108, %45, %36
%112 = phi i32 [ 37, %36 ], [ 0, %108 ], [ 37, %45 ], [ 0, %99 ], [ %89, %91 ], [ 0, %95 ]
ret i32 %112
}