#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*/ buffer;

/* Variables and functions */
scalar_t__ Ant_Create();
int /*<<< orphan*/ ProcessCommand(char);
int /*<<< orphan*/ ant_deinit();
char *ant_get_lib_version();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int main(void) {
  char buffer[1024];
  int ret = 0;
  if (Ant_Create()) {
    printf("failed to init ANT\n");
    goto out;
  }
  printf("===ANT Test===\n");
  printf("Using libantradio version:\n");
  printf("%s\n", ant_get_lib_version());
  printf("\n");
  printf("Press V to get Version\n");
  printf("Press R to Reset\n");
  printf("Press K to hard reset\n");
  printf("Press H to setup an ANT+ HRM rx channel\n");
  printf("\n");
  printf("Press A to Assign channel\n");
  printf("Press F to set radio Frequency\n");
  printf("Press I to set channel Id\n");
  printf("Press P to set channel Peroid\n");
  printf("Press O to Open channel\n");
  printf("\n");
  printf("Press E to Enable ANT\n");
  printf("Press D to Disable ANT\n");
  printf("Press S to get State\n");
  printf("\n");
  printf("Press X to eXit\n");
  while (1) {
    memset(&buffer, 0, sizeof(buffer));
    fgets(buffer, sizeof(buffer), stdin);
    ProcessCommand(buffer[0]);
    if (buffer[0] == 'X')
      goto done;
  }
done:
  ProcessCommand('R');
  sleep(1);
  ProcessCommand('D');
  ant_deinit();
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
mov    $0x0,%al
call   1060 <Ant_Create@plt>
cmp    $0x0,%rax
je     11c0 <main+0x40>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    135a <main+0x1da>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <ant_get_lib_version@plt>
mov    %rax,%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    0x2ce5(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
movsbl -0x410(%rbp),%edi
call   1030 <ProcessCommand@plt>
movsbl -0x410(%rbp),%eax
cmp    $0x58,%eax
jne    1330 <main+0x1b0>
jmp    1335 <main+0x1b5>
jmp    12e2 <main+0x162>
mov    $0x52,%edi
call   1030 <ProcessCommand@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    $0x44,%edi
call   1030 <ProcessCommand@plt>
mov    $0x0,%al
call   1090 <ant_deinit@plt>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1070 <Ant_Create@plt>
test   %rax,%rax
je     11b7 <main+0x27>
lea    0xfbe(%rip),%rdi
call   1040 <puts@plt>
jmp    1303 <main+0x173>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <ant_get_lib_version@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb4(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    0x2d3c(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
movsbl (%rsp),%edi
call   1050 <ProcessCommand@plt>
cmpb   $0x58,(%rsp)
jne    12b0 <main+0x120>
mov    $0x52,%edi
call   1050 <ProcessCommand@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x44,%edi
call   1050 <ProcessCommand@plt>
xor    %eax,%eax
call   10a0 <ant_deinit@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"failed to init ANT\0A\00"
@.str.1 = [16 x i8] c"===ANT Test===\0A\00"
@.str.2 = [28 x i8] c"Using libantradio version:\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [24 x i8] c"Press V to get Version\0A\00"
@.str.6 = [18 x i8] c"Press R to Reset\0A\00"
@.str.7 = [23 x i8] c"Press K to hard reset\0A\00"
@.str.8 = [41 x i8] c"Press H to setup an ANT+ HRM rx channel\0A\00"
@.str.9 = [27 x i8] c"Press A to Assign channel\0A\00"
@.str.10 = [32 x i8] c"Press F to set radio Frequency\0A\00"
@.str.11 = [27 x i8] c"Press I to set channel Id\0A\00"
@.str.12 = [31 x i8] c"Press P to set channel Peroid\0A\00"
@.str.13 = [25 x i8] c"Press O to Open channel\0A\00"
@.str.14 = [23 x i8] c"Press E to Enable ANT\0A\00"
@.str.15 = [24 x i8] c"Press D to Disable ANT\0A\00"
@.str.16 = [22 x i8] c"Press S to get State\0A\00"
@.str.17 = [17 x i8] c"Press X to eXit\0A\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i64 (...) @Ant_Create()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %50
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%11 = call i8* (...) @ant_get_lib_version()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.15, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.16, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.17, i64 0, i64 0))
br label %30
30: ; preds = %8, %44
%31 = bitcast [1024 x i8]* %2 to i8**
%32 = call i32 @memset(i8** %31, i32 0, i32 1024)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %33, i32 1024, i32 %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%37 = load i8, i8* %36
%38 = call i32 @ProcessCommand(i8 signext %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 88
br i1 %42, label %43, label %44
43: ; preds = %30
br label %45
44: ; preds = %30
br label %30
45: ; preds = %43
%46 = call i32 @ProcessCommand(i8 signext 82)
%47 = call i32 @sleep(i32 1)
%48 = call i32 @ProcessCommand(i8 signext 68)
%49 = call i32 (...) @ant_deinit()
br label %50
50: ; preds = %45, %6
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [15 x i8] c"===ANT Test===\00"
@str.18 = [27 x i8] c"Using libantradio version:\00"
@str.19 = [23 x i8] c"Press V to get Version\00"
@str.20 = [17 x i8] c"Press R to Reset\00"
@str.21 = [22 x i8] c"Press K to hard reset\00"
@str.22 = [40 x i8] c"Press H to setup an ANT+ HRM rx channel\00"
@str.23 = [26 x i8] c"Press A to Assign channel\00"
@str.24 = [31 x i8] c"Press F to set radio Frequency\00"
@str.25 = [26 x i8] c"Press I to set channel Id\00"
@str.26 = [30 x i8] c"Press P to set channel Peroid\00"
@str.27 = [24 x i8] c"Press O to Open channel\00"
@str.28 = [22 x i8] c"Press E to Enable ANT\00"
@str.29 = [23 x i8] c"Press D to Disable ANT\00"
@str.30 = [21 x i8] c"Press S to get State\00"
@str.31 = [16 x i8] c"Press X to eXit\00"
@str.32 = [19 x i8] c"failed to init ANT\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i64 (...) @Ant_Create()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.32, i64 0, i64 0))
br label %43
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.18, i64 0, i64 0))
%10 = tail call i8* (...) @ant_get_lib_version()
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.19, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.20, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.21, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.22, i64 0, i64 0))
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.23, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.24, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.25, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.26, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.27, i64 0, i64 0))
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.28, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.29, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.30, i64 0, i64 0))
%27 = tail call i32 @putchar(i32 10)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.31, i64 0, i64 0))
%29 = bitcast [1024 x i8]* %1 to i8**
br label %30
30: ; preds = %30, %7
%31 = call i32 @memset(i8** %29, i32 0, i32 1024)
%32 = load i32, i32* @stdin
%33 = call i32 @fgets(i8* %2, i32 1024, i32 %32)
%34 = load i8, i8* %2
%35 = call i32 @ProcessCommand(i8 signext %34)
%36 = load i8, i8* %2
%37 = icmp eq i8 %36, 88
br i1 %37, label %38, label %30
38: ; preds = %30
%39 = call i32 @ProcessCommand(i8 signext 82)
%40 = call i32 @sleep(i32 1)
%41 = call i32 @ProcessCommand(i8 signext 68)
%42 = call i32 (...) @ant_deinit()
br label %43
43: ; preds = %38, %5
ret i32 0
}