#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*/ O_RDWR;
int /*<<< orphan*/ abort();
int atoi(char *);
int /*<<< orphan*/ clean_memmory_state(int, unsigned int, int);
scalar_t__ device_reboot(int);
int /*<<< orphan*/ dump_memmory_state(int, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ get_device_info(int);
unsigned int get_log_size(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int open(char *, int /*<<< orphan*/);
char *optarg;
scalar_t__ opterr;
char optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ set_tty_speed(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ update_time(int);
int main(int argc, char **argv) {
  char *device_name = "/dev/ttyUSB0";
  int c;
  int set_time_flag = 0;
  int get_info_flag = 0;
  int get_log_size_flag = 0;
  int dump_memory_flag = 0;
  int reboot_flag = 0;
  int clean_flag = 0;
  int clean_size = 0;
  int show_help_flag = 0;
  unsigned int days_in_log = 0;
  opterr = 0;
  while ((c = getopt(argc, argv, "itsrgd:c:h")) != -1)
    switch (c) {
    case 'i':
      get_info_flag = 1;
      break;
    case 't':
      set_time_flag = 1;
      break;
    case 's':
      get_log_size_flag = 1;
      break;
    case 'g':
      get_log_size_flag = 1;
      dump_memory_flag = 1;
      break;
    case 'r':
      reboot_flag = 1;
      break;
    case 'd':
      device_name = optarg;
      break;
    case 'h':
      show_help_flag = 1;
      break;
    case 'c':
      clean_size = atoi(optarg);
      if (clean_size >= 0 && clean_size < 32) {
        get_log_size_flag = 1;
        clean_flag = 1;
      } else {
        fprintf(stderr, "?? Sorry can't clean up by '%s'.\n", optarg);
      }
      break;
    case '?':
      if (optopt == 'd' || optopt == 'c')
        fprintf(stderr, "?? Option -%c requires an argument.\n", optopt);
      else if (isprint(optopt))
        fprintf(stderr, "?? Unknown option `-%c'.\n", optopt);
      else
        fprintf(stderr, "?? Unknown option character `\\x%x'.\n", optopt);
      return 1;
    default:
      abort();
    }
  if (show_help_flag) {
    printf("Usage:\n"
           " -d device_name\tUse other device instead ttyUSB\n"
           " -i\t\tShow tracker id\n"
           " -t\t\tUpdate device time\n"
           " -s\t\tGet log size\n"
           " -g\t\tDump memmory\n"
           " -r\t\tReboot device\n"
           " -c days_count\tDelete log after days_count back\n"
           " -h\t\tShow this help\n");
    return 0;
  }
  printf("-- Will be used as tracker device: %s\n", device_name);
  int tty = open(device_name, O_RDWR);
  if (!tty) {
    printf("?? Can't open\n");
    return -1;
  }
  set_tty_speed(tty);
  if (get_info_flag)
    if (get_device_info(tty))
      return -1;
  if (reboot_flag) {
    if (device_reboot(tty))
      return -1;
    sleep(1);
    if (get_device_info(tty))
      return -1;
  }
  if (set_time_flag)
    if (update_time(tty))
      return -1;
  if (get_log_size_flag)
    days_in_log = get_log_size(tty);
  if (dump_memory_flag)
    dump_memmory_state(tty, days_in_log);
  if (clean_flag)
    clean_memmory_state(tty, days_in_log, clean_size);
  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)
lea    0xecb(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    0x2d69(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     142f <main+0x23f>
mov    -0x1c(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x35,%eax
ja     1423 <main+0x233>
mov    -0x50(%rbp),%rax
lea    0xd63(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x24(%rbp)
jmp    142a <main+0x23a>
movl   $0x1,-0x20(%rbp)
jmp    142a <main+0x23a>
movl   $0x1,-0x28(%rbp)
jmp    142a <main+0x23a>
movl   $0x1,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    142a <main+0x23a>
movl   $0x1,-0x30(%rbp)
jmp    142a <main+0x23a>
mov    0x2d08(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    142a <main+0x23a>
movl   $0x1,-0x3c(%rbp)
jmp    142a <main+0x23a>
mov    0x2ce9(%rip),%rax
mov    (%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     1341 <main+0x151>
cmpl   $0x20,-0x38(%rbp)
jge    1341 <main+0x151>
movl   $0x1,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1362 <main+0x172>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
mov    0x2ca7(%rip),%rax
mov    (%rax),%rdx
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    142a <main+0x23a>
mov    0x2c6a(%rip),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
je     138d <main+0x19d>
mov    0x2c57(%rip),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    13b3 <main+0x1c3>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
mov    0x2c3b(%rip),%rax
movsbl (%rax),%edx
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1417 <main+0x227>
mov    0x2c1e(%rip),%rax
movsbl (%rax),%edi
call   10c0 <isprint@plt>
cmp    $0x0,%eax
je     13f1 <main+0x201>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    0x2bfd(%rip),%rax
movsbl (%rax),%edx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1412 <main+0x222>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
mov    0x2bd7(%rip),%rax
movsbl (%rax),%edx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1417 <main+0x227>
movl   $0x1,-0x4(%rbp)
jmp    159e <main+0x3ae>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    125e <main+0x6e>
cmpl   $0x0,-0x3c(%rbp)
je     1453 <main+0x263>
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159e <main+0x3ae>
mov    -0x18(%rbp),%rsi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    149e <main+0x2ae>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <main+0x3ae>
mov    -0x44(%rbp),%edi
call   1090 <set_tty_speed@plt>
cmpl   $0x0,-0x24(%rbp)
je     14d3 <main+0x2e3>
mov    -0x44(%rbp),%edi
call   10d0 <get_device_info@plt>
cmp    $0x0,%rax
je     14ce <main+0x2de>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <main+0x3ae>
jmp    14d3 <main+0x2e3>
cmpl   $0x0,-0x30(%rbp)
je     1528 <main+0x338>
mov    -0x44(%rbp),%edi
call   1050 <device_reboot@plt>
cmp    $0x0,%rax
je     14fb <main+0x30b>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <main+0x3ae>
mov    $0x1,%edi
call   1110 <sleep@plt>
mov    -0x44(%rbp),%edi
call   10d0 <get_device_info@plt>
cmp    $0x0,%rax
je     1523 <main+0x333>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <main+0x3ae>
jmp    1528 <main+0x338>
cmpl   $0x0,-0x20(%rbp)
je     1555 <main+0x365>
mov    -0x44(%rbp),%edi
call   1080 <update_time@plt>
cmp    $0x0,%rax
je     1550 <main+0x360>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <main+0x3ae>
jmp    1555 <main+0x365>
cmpl   $0x0,-0x28(%rbp)
je     156a <main+0x37a>
mov    -0x44(%rbp),%edi
call   1040 <get_log_size@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     157f <main+0x38f>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1060 <dump_memmory_state@plt>
cmpl   $0x0,-0x34(%rbp)
je     1597 <main+0x3a7>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    -0x38(%rbp),%edx
call   10a0 <clean_memmory_state@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    $0x28,%rsp
mov    %rsi,0x20(%rsp)
mov    %edi,%ebp
mov    0x2da4(%rip),%rax
movq   $0x0,(%rax)
lea    0xeae(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xdca(%rip),%r12
movl   $0x0,0xc(%rsp)
xor    %edi,%edi
xor    %ecx,%ecx
movl   $0x0,0x4(%rsp)
movl   $0x0,0x10(%rsp)
xor    %edx,%edx
movl   $0x0,0x8(%rsp)
movl   $0x0,0x14(%rsp)
jmp    1276 <main+0x76>
movl   $0x1,0xc(%rsp)
mov    %ebx,%edi
mov    %r15d,%ecx
mov    %r14d,%edx
mov    %edx,%r14d
mov    %ecx,%r15d
mov    %edi,%ebx
mov    %ebp,%edi
mov    0x20(%rsp),%rsi
lea    0xe59(%rip),%rdx
call   1100 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x35,%ecx
ja     134b <main+0x14b>
mov    $0x1,%edi
movslq (%r12,%rcx,4),%rsi
add    %r12,%rsi
mov    %r15d,%ecx
mov    %r14d,%edx
jmp    *%rsi
mov    0x2d40(%rip),%rax
mov    (%rax),%r13
mov    %r13,%rdi
call   1110 <atoi@plt>
mov    $0x1,%ecx
mov    %ebx,%edi
mov    $0x1,%edx
mov    %eax,0x8(%rsp)
cmp    $0x20,%eax
jb     1276 <main+0x76>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    126e <main+0x6e>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    126e <main+0x6e>
mov    $0x1,%ecx
mov    %ebx,%edi
movl   $0x1,0x4(%rsp)
mov    %r14d,%edx
jmp    1276 <main+0x76>
movl   $0x1,0x14(%rsp)
jmp    126e <main+0x6e>
movl   $0x1,0x10(%rsp)
jmp    126e <main+0x6e>
mov    $0x1,%ecx
mov    %ebx,%edi
mov    %r14d,%edx
jmp    1276 <main+0x76>
cmp    $0xffffffff,%eax
jne    14cb <main+0x2cb>
cmpl   $0x0,0x14(%rsp)
je     13bc <main+0x1bc>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    1479 <main+0x279>
mov    0x2c63(%rip),%rbx
movzbl (%rbx),%edx
lea    -0x63(%rdx),%eax
cmp    $0x1,%al
ja     1394 <main+0x194>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
jmp    146d <main+0x26d>
movsbl %dl,%edi
call   10d0 <isprint@plt>
mov    0x2c25(%rip),%rcx
mov    (%rcx),%edi
movsbl (%rbx),%edx
test   %eax,%eax
je     1466 <main+0x266>
lea    0xd80(%rip),%rsi
jmp    146d <main+0x26d>
lea    0xdb3(%rip),%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10f0 <open@plt>
test   %eax,%eax
je     148a <main+0x28a>
mov    %eax,%r13d
mov    %eax,%edi
call   10a0 <set_tty_speed@plt>
test   %ebx,%ebx
je     140b <main+0x20b>
mov    %r13d,%edi
call   10e0 <get_device_info@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1479 <main+0x279>
cmpl   $0x0,0x10(%rsp)
je     143b <main+0x23b>
mov    %r13d,%edi
call   1060 <device_reboot@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1479 <main+0x279>
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    %r13d,%edi
call   10e0 <get_device_info@plt>
test   %rax,%rax
jne    1479 <main+0x279>
cmpl   $0x0,0xc(%rsp)
je     1454 <main+0x254>
mov    %r13d,%edi
call   1090 <update_time@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1479 <main+0x279>
test   %r15d,%r15d
je     149d <main+0x29d>
mov    %r13d,%edi
call   1050 <get_log_size@plt>
mov    %eax,%r12d
jmp    14a0 <main+0x2a0>
lea    0xce4(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0c(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
jmp    1479 <main+0x279>
xor    %r12d,%r12d
mov    0x4(%rsp),%eax
test   %eax,%eax
je     14b3 <main+0x2b3>
mov    %r13d,%edi
mov    %r12d,%esi
call   1070 <dump_memmory_state@plt>
xor    %ebp,%ebp
test   %r14d,%r14d
je     1479 <main+0x279>
mov    %r13d,%edi
mov    %r12d,%esi
mov    0x8(%rsp),%edx
call   10b0 <clean_memmory_state@plt>
jmp    1479 <main+0x279>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@opterr = global i64 0
@.str.1 = [11 x i8] c"itsrgd:c:h\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [34 x i8] c"?? Sorry can't clean up by '%s'.\0A\00"
@optopt = global i8 0
@.str.3 = [37 x i8] c"?? Option -%c requires an argument.\0A\00"
@.str.4 = [26 x i8] c"?? Unknown option `-%c'.\0A\00"
@.str.5 = [37 x i8] c"?? Unknown option character `\\x%x'.\0A\00"
@.str.6 = [224 x i8] c"Usage:\0A -d device_name\09Use other device instead ttyUSB\0A -i\09\09Show tracker id\0A -t\09\09Update device time\0A -s\09\09Get log size\0A -g\09\09Dump memmory\0A -r\09\09Reboot device\0A -c days_count\09Delete log after days_count back\0A -h\09\09Show this help\0A\00"
@.str.7 = [39 x i8] c"-- Will be used as tracker device: %s\0A\00"
@O_RDWR = global i32 0
@.str.8 = [15 x i8] c"?? Can't open\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i64 0, i64* @opterr
br label %18
18: ; preds = %78, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %21, i32* %7
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %79
23: ; preds = %18
%24 = load i32, i32* %7
switch i32 %24, label %76 [
i32 105, label %25
i32 116, label %26
i32 115, label %27
i32 103, label %28
i32 114, label %29
i32 100, label %30
i32 104, label %32
i32 99, label %33
i32 63, label %47
]
25: ; preds = %23
store i32 1, i32* %9
br label %78
26: ; preds = %23
store i32 1, i32* %8
br label %78
27: ; preds = %23
store i32 1, i32* %10
br label %78
28: ; preds = %23
store i32 1, i32* %10
store i32 1, i32* %11
br label %78
29: ; preds = %23
store i32 1, i32* %12
br label %78
30: ; preds = %23
%31 = load i8*, i8** @optarg
store i8* %31, i8** %6
br label %78
32: ; preds = %23
store i32 1, i32* %15
br label %78
33: ; preds = %23
%34 = load i8*, i8** @optarg
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %14
%36 = load i32, i32* %14
%37 = icmp sge i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 32
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 1, i32* %10
store i32 1, i32* %13
br label %46
42: ; preds = %38, %33
%43 = load i32, i32* @stderr
%44 = load i8*, i8** @optarg
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %41
br label %78
47: ; preds = %23
%48 = load i8, i8* @optopt
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 100
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i8, i8* @optopt
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 99
br i1 %54, label %55, label %60
55: ; preds = %51, %47
%56 = load i32, i32* @stderr
%57 = load i8, i8* @optopt
%58 = sext i8 %57 to i32
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %75
60: ; preds = %51
%61 = load i8, i8* @optopt
%62 = call i32 @isprint(i8 signext %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = load i8, i8* @optopt
%67 = sext i8 %66 to i32
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %74
69: ; preds = %60
%70 = load i32, i32* @stderr
%71 = load i8, i8* @optopt
%72 = sext i8 %71 to i32
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %69, %64
br label %75
75: ; preds = %74, %55
store i32 1, i32* %3
br label %151
76: ; preds = %23
%77 = call i32 (...) @abort()
unreachable
78: ; preds = %46, %32, %30, %29, %28, %27, %26, %25
br label %18
79: ; preds = %18
%80 = load i32, i32* %15
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([224 x i8], [224 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %151
84: ; preds = %79
%85 = load i8*, i8** %6
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %85)
%87 = load i8*, i8** %6
%88 = load i32, i32* @O_RDWR
%89 = call i32 @open(i8* %87, i32 %88)
store i32 %89, i32* %17
%90 = load i32, i32* %17
%91 = icmp ne i32 %90, 0
br i1 %91, label %94, label %92
92: ; preds = %84
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %151
94: ; preds = %84
%95 = load i32, i32* %17
%96 = call i32 @set_tty_speed(i32 %95)
%97 = load i32, i32* %9
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %105
99: ; preds = %94
%100 = load i32, i32* %17
%101 = call i64 @get_device_info(i32 %100)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %99
store i32 -1, i32* %3
br label %151
104: ; preds = %99
br label %105
105: ; preds = %104, %94
%106 = load i32, i32* %12
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %120
108: ; preds = %105
%109 = load i32, i32* %17
%110 = call i64 @device_reboot(i32 %109)
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %108
store i32 -1, i32* %3
br label %151
113: ; preds = %108
%114 = call i32 @sleep(i32 1)
%115 = load i32, i32* %17
%116 = call i64 @get_device_info(i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %113
store i32 -1, i32* %3
br label %151
119: ; preds = %113
br label %120
120: ; preds = %119, %105
%121 = load i32, i32* %8
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %129
123: ; preds = %120
%124 = load i32, i32* %17
%125 = call i64 @update_time(i32 %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %128
127: ; preds = %123
store i32 -1, i32* %3
br label %151
128: ; preds = %123
br label %129
129: ; preds = %128, %120
%130 = load i32, i32* %10
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %135
132: ; preds = %129
%133 = load i32, i32* %17
%134 = call i32 @get_log_size(i32 %133)
store i32 %134, i32* %16
br label %135
135: ; preds = %132, %129
%136 = load i32, i32* %11
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %142
138: ; preds = %135
%139 = load i32, i32* %17
%140 = load i32, i32* %16
%141 = call i32 @dump_memmory_state(i32 %139, i32 %140)
br label %142
142: ; preds = %138, %135
%143 = load i32, i32* %13
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %150
145: ; preds = %142
%146 = load i32, i32* %17
%147 = load i32, i32* %16
%148 = load i32, i32* %14
%149 = call i32 @clean_memmory_state(i32 %146, i32 %147, i32 %148)
br label %150
150: ; preds = %145, %142
store i32 0, i32* %3
br label %151
151: ; preds = %150, %127, %118, %112, %103, %92, %82, %75
%152 = load i32, i32* %3
ret i32 %152
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@opterr = global i64 0
@.str.1 = [11 x i8] c"itsrgd:c:h\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [34 x i8] c"?? Sorry can't clean up by '%s'.\0A\00"
@optopt = global i8 0
@.str.3 = [37 x i8] c"?? Option -%c requires an argument.\0A\00"
@.str.4 = [26 x i8] c"?? Unknown option `-%c'.\0A\00"
@.str.5 = [37 x i8] c"?? Unknown option character `\\x%x'.\0A\00"
@.str.7 = [39 x i8] c"-- Will be used as tracker device: %s\0A\00"
@O_RDWR = global i32 0
@str = [14 x i8] c"?? Can't open\00"
@str.9 = [223 x i8] c"Usage:\0A -d device_name\09Use other device instead ttyUSB\0A -i\09\09Show tracker id\0A -t\09\09Update device time\0A -s\09\09Get log size\0A -g\09\09Dump memmory\0A -r\09\09Reboot device\0A -c days_count\09Delete log after days_count back\0A -h\09\09Show this help\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %25, %2
%4 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %2 ], [ %26, %25 ]
%5 = phi i32 [ 0, %2 ], [ %27, %25 ]
%6 = phi i32 [ 0, %2 ], [ %28, %25 ]
%7 = phi i32 [ 0, %2 ], [ %29, %25 ]
%8 = phi i32 [ 0, %2 ], [ %30, %25 ]
%9 = phi i32 [ 0, %2 ], [ %31, %25 ]
%10 = phi i32 [ 0, %2 ], [ %32, %25 ]
%11 = phi i32 [ 0, %2 ], [ %33, %25 ]
%12 = phi i32 [ 0, %2 ], [ %34, %25 ]
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
switch i32 %13, label %56 [
i32 -1, label %58
i32 105, label %25
i32 116, label %14
i32 115, label %15
i32 103, label %16
i32 114, label %17
i32 100, label %18
i32 104, label %20
i32 99, label %21
i32 63, label %38
]
14: ; preds = %3
br label %25
15: ; preds = %3
br label %25
16: ; preds = %3
br label %25
17: ; preds = %3
br label %25
18: ; preds = %3
%19 = load i8*, i8** @optarg
br label %25
20: ; preds = %3
br label %25
21: ; preds = %3
%22 = load i8*, i8** @optarg
%23 = tail call i32 @atoi(i8* %22)
%24 = icmp ult i32 %23, 32
br i1 %24, label %25, label %35
25: ; preds = %21, %3, %35, %20, %18, %17, %16, %15, %14
%26 = phi i8* [ %4, %35 ], [ %4, %20 ], [ %19, %18 ], [ %4, %17 ], [ %4, %16 ], [ %4, %15 ], [ %4, %14 ], [ %4, %3 ], [ %4, %21 ]
%27 = phi i32 [ %5, %35 ], [ %5, %20 ], [ %5, %18 ], [ %5, %17 ], [ %5, %16 ], [ %5, %15 ], [ 1, %14 ], [ %5, %3 ], [ %5, %21 ]
%28 = phi i32 [ %6, %35 ], [ %6, %20 ], [ %6, %18 ], [ %6, %17 ], [ %6, %16 ], [ %6, %15 ], [ %6, %14 ], [ 1, %3 ], [ %6, %21 ]
%29 = phi i32 [ %7, %35 ], [ %7, %20 ], [ %7, %18 ], [ %7, %17 ], [ 1, %16 ], [ 1, %15 ], [ %7, %14 ], [ %7, %3 ], [ 1, %21 ]
%30 = phi i32 [ %8, %35 ], [ %8, %20 ], [ %8, %18 ], [ %8, %17 ], [ 1, %16 ], [ %8, %15 ], [ %8, %14 ], [ %8, %3 ], [ %8, %21 ]
%31 = phi i32 [ %9, %35 ], [ %9, %20 ], [ %9, %18 ], [ 1, %17 ], [ %9, %16 ], [ %9, %15 ], [ %9, %14 ], [ %9, %3 ], [ %9, %21 ]
%32 = phi i32 [ %10, %35 ], [ %10, %20 ], [ %10, %18 ], [ %10, %17 ], [ %10, %16 ], [ %10, %15 ], [ %10, %14 ], [ %10, %3 ], [ 1, %21 ]
%33 = phi i32 [ %23, %35 ], [ %11, %20 ], [ %11, %18 ], [ %11, %17 ], [ %11, %16 ], [ %11, %15 ], [ %11, %14 ], [ %11, %3 ], [ %23, %21 ]
%34 = phi i32 [ %12, %35 ], [ 1, %20 ], [ %12, %18 ], [ %12, %17 ], [ %12, %16 ], [ %12, %15 ], [ %12, %14 ], [ %12, %3 ], [ %12, %21 ]
br label %3
35: ; preds = %21
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %25
38: ; preds = %3
%39 = load i8, i8* @optopt
%40 = add i8 %39, -99
%41 = icmp ult i8 %40, 2
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = zext i8 %39 to i32
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %102
46: ; preds = %38
%47 = tail call i32 @isprint(i8 signext %39)
%48 = icmp eq i32 %47, 0
%49 = load i32, i32* @stderr
%50 = load i8, i8* @optopt
%51 = sext i8 %50 to i32
br i1 %48, label %54, label %52
52: ; preds = %46
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %102
54: ; preds = %46
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %102
56: ; preds = %3
%57 = tail call i32 (...) @abort()
unreachable
58: ; preds = %3
%59 = icmp eq i32 %12, 0
br i1 %59, label %62, label %60
60: ; preds = %58
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([223 x i8], [223 x i8]* @str.9, i64 0, i64 0))
br label %102
62: ; preds = %58
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%64 = load i32, i32* @O_RDWR
%65 = tail call i32 @open(i8* %4, i32 %64)
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %102
69: ; preds = %62
%70 = tail call i32 @set_tty_speed(i32 %65)
%71 = icmp eq i32 %6, 0
br i1 %71, label %75, label %72
72: ; preds = %69
%73 = tail call i64 @get_device_info(i32 %65)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %102
75: ; preds = %72, %69
%76 = icmp eq i32 %9, 0
br i1 %76, label %84, label %77
77: ; preds = %75
%78 = tail call i64 @device_reboot(i32 %65)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %102
80: ; preds = %77
%81 = tail call i32 @sleep(i32 1)
%82 = tail call i64 @get_device_info(i32 %65)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %102
84: ; preds = %80, %75
%85 = icmp eq i32 %5, 0
br i1 %85, label %89, label %86
86: ; preds = %84
%87 = tail call i64 @update_time(i32 %65)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %102
89: ; preds = %86, %84
%90 = icmp eq i32 %7, 0
br i1 %90, label %93, label %91
91: ; preds = %89
%92 = tail call i32 @get_log_size(i32 %65)
br label %93
93: ; preds = %91, %89
%94 = phi i32 [ %92, %91 ], [ 0, %89 ]
%95 = icmp eq i32 %8, 0
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = tail call i32 @dump_memmory_state(i32 %65, i32 %94)
br label %98
98: ; preds = %96, %93
%99 = icmp eq i32 %10, 0
br i1 %99, label %102, label %100
100: ; preds = %98
%101 = tail call i32 @clean_memmory_state(i32 %65, i32 %94, i32 %11)
br label %102
102: ; preds = %67, %72, %77, %80, %86, %100, %98, %42, %54, %52, %60
%103 = phi i32 [ 0, %60 ], [ 1, %52 ], [ 1, %54 ], [ 1, %42 ], [ -1, %67 ], [ -1, %72 ], [ -1, %77 ], [ -1, %80 ], [ -1, %86 ], [ 0, %100 ], [ 0, %98 ]
ret i32 %103
}