#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*/ uint8_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct pkt {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int connect_to_ser2net();
scalar_t__ decode_packet(struct pkt *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ init_camera_time_bcd(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ read_console(int /*<<< orphan*/, int);
struct pkt *read_packet(int);
struct pkt *read_packet_from_hex_string(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ send_packet(int, int, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd, i, ret;
  fd_set rfds;
  struct timeval tv;
  struct pkt *pkt;
  for (i = 2; i < argc && !strcmp(argv[1], "-x"); i++) {
    char *arg = argv[i];
    pkt = read_packet_from_hex_string(arg);
    decode_packet(pkt);
    if (i == argc - 1)
      return 0;
  }
  if ((fd = connect_to_ser2net()) < 0) {
    fprintf(stderr, "ERROR: Failed to connect to DJI Phantom\n");
    return -1;
  }
  printf("* Connected\n");
  if (send_packet(fd, 0x08, 0x04, (uint8_t *)"\x01", 1) < 0)
    return -1;
  if (init_camera_time_bcd(fd) < 0)
    return -1;
  FD_ZERO(&rfds);
  for (;;) {
    fflush(stdout);
    FD_SET(fd, &rfds);
    FD_SET(fileno(stdin), &rfds);
    tv.tv_sec = 1;
    tv.tv_usec = 500000;
    if ((ret = select(fd + 1, &rfds, NULL, NULL, &tv)) < 0) {
      fprintf(stderr, "ERROR: select() failed: %s\n", strerror(errno));
      close(fd);
      return -1;
    }
    if (ret == 0) {
      if (send_packet(fd, 0x0a, 0x49, (uint8_t *)"", 1) < 0)
        break;
      if (send_packet(fd, 0x0a, 0x53, (uint8_t *)"", 1) < 0)
        break;
    }
    if (FD_ISSET(fd, &rfds)) {
      if ((pkt = read_packet(fd)) == NULL)
        break;
      if (decode_packet(pkt))
        break;
    }
    if (FD_ISSET(fileno(stdin), &rfds)) {
      if (read_console(stdin, fd))
        break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x39(%rbp)
jge    126d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda3(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    127d <main+0x5d>
jmp    12d3 <main+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <read_packet_from_hex_string@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1110 <decode_packet@plt>
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12c0 <main+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    1527 <main+0x307>
jmp    12c5 <main+0xa5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123d <main+0x1d>
mov    $0x0,%al
call   1030 <connect_to_ser2net@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1309 <main+0xe9>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1527 <main+0x307>
lea    0xd1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
mov    $0x4,%edx
lea    0xd10(%rip),%rcx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
cmp    $0x0,%rax
jge    134a <main+0x12a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1527 <main+0x307>
mov    -0x14(%rbp),%edi
call   10f0 <init_camera_time_bcd@plt>
cmp    $0x0,%rax
jge    1368 <main+0x148>
movl   $0xffffffff,-0x4(%rbp)
jmp    1527 <main+0x307>
lea    -0x20(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1130 <FD_SET@plt>
movl   $0x1,-0x28(%rbp)
movl   $0x7a120,-0x24(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    141a <main+0x1fa>
mov    0x2bf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xc3c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1527 <main+0x307>
cmpl   $0x0,-0x1c(%rbp)
jne    1485 <main+0x265>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x49,%edx
lea    0xc02(%rip),%rcx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
cmp    $0x0,%rax
jge    1452 <main+0x232>
jmp    1520 <main+0x300>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
mov    $0x53,%edx
lea    0xbd4(%rip),%rcx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
cmp    $0x0,%rax
jge    1480 <main+0x260>
jmp    1520 <main+0x300>
jmp    1485 <main+0x265>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14d3 <main+0x2b3>
mov    -0x14(%rbp),%edi
call   1060 <read_packet@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    14b6 <main+0x296>
jmp    1520 <main+0x300>
mov    -0x30(%rbp),%rdi
call   1110 <decode_packet@plt>
cmp    $0x0,%rax
je     14ce <main+0x2ae>
jmp    1520 <main+0x300>
jmp    14d3 <main+0x2b3>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
call   10b0 <fileno@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     151b <main+0x2fb>
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1140 <read_console@plt>
cmp    $0x0,%rax
je     1516 <main+0x2f6>
jmp    1520 <main+0x300>
jmp    151b <main+0x2fb>
jmp    1371 <main+0x151>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jl     128e <main+0x6e>
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
lea    0xdbc(%rip),%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    128e <main+0x6e>
add    $0xffffffff,%r15d
mov    $0x2,%ebp
lea    0xda3(%rip),%r14
nopl   (%rax)
mov    (%rbx,%rbp,8),%rdi
call   1070 <read_packet_from_hex_string@plt>
mov    %rax,%rdi
call   1110 <decode_packet@plt>
cmp    %rbp,%r15
je     1418 <main+0x1f8>
add    $0x1,%rbp
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
je     1260 <main+0x40>
xor    %eax,%eax
call   1040 <connect_to_ser2net@plt>
test   %eax,%eax
js     141d <main+0x1fd>
mov    %eax,%r14d
lea    0xda3(%rip),%rdi
call   1030 <puts@plt>
lea    0xd79(%rip),%rcx
mov    %r14d,%edi
mov    $0x8,%esi
mov    $0x4,%edx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
js     143a <main+0x21a>
mov    %r14d,%edi
call   10f0 <init_camera_time_bcd@plt>
test   %rax,%rax
js     143a <main+0x21a>
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r14d,%r15d
add    $0x1,%r15d
mov    0x2ce2(%rip),%rbx
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
mov    (%rbx),%edi
call   10b0 <fileno@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
movabs $0x7a12000000001,%rax
mov    %rax,0x8(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10d0 <select@plt>
test   %eax,%eax
js     144c <main+0x22c>
jne    13be <main+0x19e>
mov    %r15d,%r12d
mov    %r14d,%edi
mov    $0xa,%esi
mov    $0x49,%edx
lea    0xcb1(%rip),%r15
mov    %r15,%rcx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
xor    %r13d,%r13d
test   %rax,%rax
js     143a <main+0x21a>
mov    %r14d,%edi
mov    $0xa,%esi
mov    $0x53,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1100 <send_packet@plt>
test   %rax,%rax
mov    %r12d,%r15d
lea    0x8(%rsp),%r12
js     143a <main+0x21a>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     13eb <main+0x1cb>
mov    %r14d,%edi
call   1060 <read_packet@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     143a <main+0x21a>
mov    %rax,%rdi
call   1110 <decode_packet@plt>
test   %rax,%rax
jne    143a <main+0x21a>
mov    (%rbx),%edi
call   10b0 <fileno@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1310 <main+0xf0>
mov    (%rbx),%edi
mov    %r14d,%esi
call   1140 <read_console@plt>
test   %rax,%rax
je     1310 <main+0xf0>
xor    %r13d,%r13d
jmp    143a <main+0x21a>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xbd6(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b85(%rip),%rax
mov    (%rax),%ebp
mov    0x2b74(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbc4(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    1434 <main+0x214>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.pkt = type { i32 }
@.str = [3 x i8] c"-x\00"
@stderr = global i32 0
@.str.1 = [41 x i8] c"ERROR: Failed to connect to DJI Phantom\0A\00"
@.str.2 = [13 x i8] c"* Connected\0A\00"
@.str.3 = [2 x i8] c"\01\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.4 = [28 x i8] c"ERROR: select() failed: %s\0A\00"
@errno = global i32 0
@.str.5 = [1 x i8] zeroinitializer
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 %struct.timeval
%11 = alloca %struct.pkt*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %7
br label %13
13: ; preds = %42, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %17, %13
%25 = phi i1 [ false, %13 ], [ %23, %17 ]
br i1 %25, label %26, label %45
26: ; preds = %24
%27 = load i8**, i8*** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %12
%32 = load i8*, i8** %12
%33 = call %struct.pkt* @read_packet_from_hex_string(i8* %32)
store %struct.pkt* %33, %struct.pkt** %11
%34 = load %struct.pkt*, %struct.pkt** %11
%35 = call i64 @decode_packet(%struct.pkt* %34)
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 1
%39 = icmp eq i32 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %26
store i32 0, i32* %3
br label %128
41: ; preds = %26
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %13
45: ; preds = %24
%46 = call i32 (...) @connect_to_ser2net()
store i32 %46, i32* %6
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %128
51: ; preds = %45
%52 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = call i64 @send_packet(i32 %53, i32 8, i32 4, i32* bitcast ([2 x i8]* @.str.3 to i32*), i32 1)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 -1, i32* %3
br label %128
57: ; preds = %51
%58 = load i32, i32* %6
%59 = call i64 @init_camera_time_bcd(i32 %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %57
store i32 -1, i32* %3
br label %128
62: ; preds = %57
%63 = call i32 @FD_ZERO(i32* %9)
br label %64
64: ; preds = %126, %62
%65 = load i32, i32* @stdout
%66 = call i32 @fflush(i32 %65)
%67 = load i32, i32* %6
%68 = call i32 @FD_SET(i32 %67, i32* %9)
%69 = load i32, i32* @stdin
%70 = call i32 @fileno(i32 %69)
%71 = call i32 @FD_SET(i32 %70, i32* %9)
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
store i32 1, i32* %72
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i32 500000, i32* %73
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
%76 = call i32 @select(i32 %75, i32* %9, i32* null, i32* null, %struct.timeval* %10)
store i32 %76, i32* %8
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %64
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
store i32 -1, i32* %3
br label %128
85: ; preds = %64
%86 = load i32, i32* %8
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %99
88: ; preds = %85
%89 = load i32, i32* %6
%90 = call i64 @send_packet(i32 %89, i32 10, i32 73, i32* bitcast ([1 x i8]* @.str.5 to i32*), i32 1)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %88
br label %127
93: ; preds = %88
%94 = load i32, i32* %6
%95 = call i64 @send_packet(i32 %94, i32 10, i32 83, i32* bitcast ([1 x i8]* @.str.5 to i32*), i32 1)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %93
br label %127
98: ; preds = %93
br label %99
99: ; preds = %98, %85
%100 = load i32, i32* %6
%101 = call i64 @FD_ISSET(i32 %100, i32* %9)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %114
103: ; preds = %99
%104 = load i32, i32* %6
%105 = call %struct.pkt* @read_packet(i32 %104)
store %struct.pkt* %105, %struct.pkt** %11
%106 = icmp eq %struct.pkt* %105, null
br i1 %106, label %107, label %108
107: ; preds = %103
br label %127
108: ; preds = %103
%109 = load %struct.pkt*, %struct.pkt** %11
%110 = call i64 @decode_packet(%struct.pkt* %109)
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %108
br label %127
113: ; preds = %108
br label %114
114: ; preds = %113, %99
%115 = load i32, i32* @stdin
%116 = call i32 @fileno(i32 %115)
%117 = call i64 @FD_ISSET(i32 %116, i32* %9)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %126
119: ; preds = %114
%120 = load i32, i32* @stdin
%121 = load i32, i32* %6
%122 = call i64 @read_console(i32 %120, i32 %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %124, label %125
124: ; preds = %119
br label %127
125: ; preds = %119
br label %126
126: ; preds = %125, %114
br label %64
127: ; preds = %124, %112, %107, %97, %92
store i32 0, i32* %3
br label %128
128: ; preds = %127, %78, %61, %56, %48, %40
%129 = load i32, i32* %3
ret i32 %129
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.pkt = type { i32 }
@.str = [3 x i8] c"-x\00"
@stderr = global i32 0
@.str.1 = [41 x i8] c"ERROR: Failed to connect to DJI Phantom\0A\00"
@.str.3 = [2 x i8] c"\01\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.4 = [28 x i8] c"ERROR: select() failed: %s\0A\00"
@errno = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@str = [12 x i8] c"* Connected\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp sgt i32 %0, 2
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = add nsw i32 %0, -1
%11 = zext i32 %10 to i64
%12 = load i8*, i8** %9
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %27
15: ; preds = %20
%16 = add nuw nsw i64 %21, 1
%17 = load i8*, i8** %9
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %8, %15
%21 = phi i64 [ %16, %15 ], [ 2, %8 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call %struct.pkt* @read_packet_from_hex_string(i8* %23)
%25 = tail call i64 @decode_packet(%struct.pkt* %24)
%26 = icmp eq i64 %21, %11
br i1 %26, label %87, label %15
27: ; preds = %15, %8, %2
%28 = tail call i32 (...) @connect_to_ser2net()
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %87
33: ; preds = %27
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%35 = tail call i64 @send_packet(i32 %28, i32 8, i32 4, i32* bitcast ([2 x i8]* @.str.3 to i32*), i32 1)
%36 = icmp slt i64 %35, 0
br i1 %36, label %87, label %37
37: ; preds = %33
%38 = tail call i64 @init_camera_time_bcd(i32 %28)
%39 = icmp slt i64 %38, 0
br i1 %39, label %87, label %40
40: ; preds = %37
%41 = call i32 @FD_ZERO(i32* %3)
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%44 = add nuw nsw i32 %28, 1
br label %45
45: ; preds = %86, %40
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
%48 = call i32 @FD_SET(i32 %28, i32* %3)
%49 = load i32, i32* @stdin
%50 = call i32 @fileno(i32 %49)
%51 = call i32 @FD_SET(i32 %50, i32* %3)
store i32 1, i32* %42
store i32 500000, i32* %43
%52 = call i32 @select(i32 %44, i32* %3, i32* null, i32* null, %struct.timeval* %4)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = call i32 @close(i32 %28)
br label %87
60: ; preds = %45
%61 = icmp eq i32 %52, 0
br i1 %61, label %62, label %68
62: ; preds = %60
%63 = call i64 @send_packet(i32 %28, i32 10, i32 73, i32* bitcast ([1 x i8]* @.str.5 to i32*), i32 1)
%64 = icmp slt i64 %63, 0
br i1 %64, label %87, label %65
65: ; preds = %62
%66 = call i64 @send_packet(i32 %28, i32 10, i32 83, i32* bitcast ([1 x i8]* @.str.5 to i32*), i32 1)
%67 = icmp slt i64 %66, 0
br i1 %67, label %87, label %68
68: ; preds = %65, %60
%69 = call i64 @FD_ISSET(i32 %28, i32* %3)
%70 = icmp eq i64 %69, 0
br i1 %70, label %77, label %71
71: ; preds = %68
%72 = call %struct.pkt* @read_packet(i32 %28)
%73 = icmp eq %struct.pkt* %72, null
br i1 %73, label %87, label %74
74: ; preds = %71
%75 = call i64 @decode_packet(%struct.pkt* %72)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %87
77: ; preds = %74, %68
%78 = load i32, i32* @stdin
%79 = call i32 @fileno(i32 %78)
%80 = call i64 @FD_ISSET(i32 %79, i32* %3)
%81 = icmp eq i64 %80, 0
br i1 %81, label %86, label %82
82: ; preds = %77
%83 = load i32, i32* @stdin
%84 = call i64 @read_console(i32 %83, i32 %28)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %82, %77
br label %45
87: ; preds = %20, %62, %65, %71, %74, %82, %37, %33, %54, %30
%88 = phi i32 [ -1, %30 ], [ -1, %54 ], [ -1, %33 ], [ -1, %37 ], [ 0, %82 ], [ 0, %74 ], [ 0, %71 ], [ 0, %65 ], [ 0, %62 ], [ 0, %20 ]
ret i32 %88
}