#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 */
scalar_t__ check_ack();
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, int);
int read_one();
scalar_t__ stm_cmd(int);
int stm_ver1(int verbose) {
  int num;
  int i;
  int val;
  int rv;
  if (stm_cmd(0x00) == 0)
    error("GET command rejected");
  num = read_one();
  for (i = 0; i <= num; i++) {
    val = read_one();
    if (i == 0)
      rv = val;
    if (verbose)
      if (i == 0)
        printf("Bootloader version = %02x\n", val);
      else
        printf("Command recognized = %02x\n", val);
  }
  if (check_ack() == 0)
    error("GET version ended badly");
  return rv;
}


x86 assembly (clang, -O0):
<stm_ver1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %edi,%edi
call   1030 <stm_cmd@plt>
cmp    $0x0,%rax
jne    1178 <stm_ver1+0x28>
lea    0xe8d(%rip),%rdi
call   1070 <error@plt>
mov    $0x0,%al
call   1050 <read_one@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11fe <stm_ver1+0xae>
mov    $0x0,%al
call   1050 <read_one@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11af <stm_ver1+0x5f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11eb <stm_ver1+0x9b>
cmpl   $0x0,-0xc(%rbp)
jne    11d7 <stm_ver1+0x87>
mov    -0x10(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
jmp    11e6 <stm_ver1+0x96>
mov    -0x10(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1060 <printf@plt>
jmp    11eb <stm_ver1+0x9b>
jmp    11f0 <stm_ver1+0xa0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <stm_ver1+0x39>
mov    $0x0,%al
call   1040 <check_ack@plt>
cmp    $0x0,%rax
jne    121b <stm_ver1+0xcb>
lea    0xe35(%rip),%rdi
call   1070 <error@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stm_ver1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %edi,%edi
call   1030 <stm_cmd@plt>
test   %rax,%rax
jne    1171 <stm_ver1+0x21>
lea    0xe94(%rip),%rdi
call   1070 <error@plt>
xor    %eax,%eax
call   1050 <read_one@plt>
test   %eax,%eax
js     11cc <stm_ver1+0x7c>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <read_one@plt>
mov    %eax,%r14d
test   %ebx,%ebx
je     119b <stm_ver1+0x4b>
lea    0xe82(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
test   %ebp,%ebp
je     11cc <stm_ver1+0x7c>
lea    0xe8a(%rip),%r15
jmp    11b5 <stm_ver1+0x65>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     11cc <stm_ver1+0x7c>
xor    %eax,%eax
call   1050 <read_one@plt>
test   %ebx,%ebx
je     11b0 <stm_ver1+0x60>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
jmp    11b0 <stm_ver1+0x60>
xor    %eax,%eax
call   1040 <check_ack@plt>
test   %rax,%rax
jne    11e4 <stm_ver1+0x94>
lea    0xe6c(%rip),%rdi
call   1070 <error@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"GET command rejected\00"
@.str.1 = [27 x i8] c"Bootloader version = %02x\0A\00"
@.str.2 = [27 x i8] c"Command recognized = %02x\0A\00"
@.str.3 = [24 x i8] c"GET version ended badly\00"
define i32 @stm_ver1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i64 @stm_cmd(i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 (...) @read_one()
store i32 %12, i32* %3
store i32 0, i32* %4
br label %13
13: ; preds = %37, %11
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = call i32 (...) @read_one()
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* %5
store i32 %22, i32* %6
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %5
%31 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %35
32: ; preds = %26
%33 = load i32, i32* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %13
40: ; preds = %13
%41 = call i64 (...) @check_ack()
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [21 x i8] c"GET command rejected\00"
@.str.1 = [27 x i8] c"Bootloader version = %02x\0A\00"
@.str.2 = [27 x i8] c"Command recognized = %02x\0A\00"
@.str.3 = [24 x i8] c"GET version ended badly\00"
define i32 @stm_ver1(i32 %0) {
%2 = tail call i64 @stm_cmd(i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 (...) @read_one()
%8 = icmp slt i32 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = icmp eq i32 %0, 0
%11 = tail call i32 (...) @read_one()
br i1 %10, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %14
14: ; preds = %12, %9
%15 = icmp eq i32 %7, 0
br i1 %15, label %24, label %16
16: ; preds = %14, %21
%17 = phi i32 [ %22, %21 ], [ 1, %14 ]
%18 = tail call i32 (...) @read_one()
br i1 %10, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %21
21: ; preds = %16, %19
%22 = add nuw i32 %17, 1
%23 = icmp eq i32 %17, %7
br i1 %23, label %24, label %16
24: ; preds = %21, %14, %6
%25 = phi i32 [ undef, %6 ], [ %11, %14 ], [ %11, %21 ]
%26 = tail call i64 (...) @check_ack()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
ret i32 %25
}