#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*/ atoi(char *);
int /*<<< orphan*/ bs_chip_final();
int /*<<< orphan*/ bs_chip_init();
int /*<<< orphan*/ bs_cmd_flag_hif_mode_cmd();
int /*<<< orphan*/ bs_cmd_ld_img_pgm(int, char *);
int /*<<< orphan*/ bs_cmd_set_rotmode(int /*<<< orphan*/);
int /*<<< orphan*/ bs_cmd_upd_full(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ bs_cmd_wait_for_bit(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "Usage: bs_load_img <rotation> <image.pgm>\n\r");
    return (-1);
  }
  bs_chip_init();
  bs_cmd_flag_hif_mode_cmd();
  bs_cmd_set_rotmode((atoi((char *)*++argv)));
  bs_cmd_ld_img_pgm(3, *++argv);
  bs_cmd_wait_for_bit(0x338, 0, 0);
  bs_cmd_wait_for_bit(0x338, 3, 0);
  bs_cmd_upd_full(3, 15, 0);
  bs_cmd_wait_for_bit(0x338, 0, 0);
  bs_cmd_wait_for_bit(0x338, 3, 0);
  bs_chip_final();
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d1 <main+0x41>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <main+0xe8>
mov    $0x0,%al
call   1040 <bs_chip_init@plt>
mov    $0x0,%al
call   1030 <bs_cmd_flag_hif_mode_cmd@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   10a0 <bs_cmd_set_rotmode@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rsi
mov    $0x3,%edi
call   1070 <bs_cmd_ld_img_pgm@plt>
mov    $0x338,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x338,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x3,%edi
mov    $0xf,%esi
xor    %edx,%edx
call   1050 <bs_cmd_upd_full@plt>
mov    $0x338,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x338,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x0,%al
call   1090 <bs_chip_final@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1225 <main+0x95>
mov    %rsi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <bs_chip_init@plt>
xor    %eax,%eax
call   1030 <bs_cmd_flag_hif_mode_cmd@plt>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   10a0 <bs_cmd_set_rotmode@plt>
mov    0x10(%rbx),%rsi
mov    $0x3,%edi
call   1070 <bs_cmd_ld_img_pgm@plt>
mov    $0x338,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x338,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x3,%edi
mov    $0xf,%esi
xor    %edx,%edx
call   1050 <bs_cmd_upd_full@plt>
mov    $0x338,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
mov    $0x338,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1080 <bs_cmd_wait_for_bit@plt>
xor    %eax,%eax
call   1090 <bs_chip_final@plt>
jmp    123f <main+0xaf>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: bs_load_img <rotation> <image.pgm>\0A\0D\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
11: ; preds = %2
%12 = call i32 (...) @bs_chip_init()
%13 = call i32 (...) @bs_cmd_flag_hif_mode_cmd()
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
%18 = call i32 @bs_cmd_set_rotmode(i32 %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @bs_cmd_ld_img_pgm(i32 3, i8* %21)
%23 = call i32 @bs_cmd_wait_for_bit(i32 824, i32 0, i32 0)
%24 = call i32 @bs_cmd_wait_for_bit(i32 824, i32 3, i32 0)
%25 = call i32 @bs_cmd_upd_full(i32 3, i32 15, i32 0)
%26 = call i32 @bs_cmd_wait_for_bit(i32 824, i32 0, i32 0)
%27 = call i32 @bs_cmd_wait_for_bit(i32 824, i32 3, i32 0)
%28 = call i32 (...) @bs_chip_final()
store i32 0, i32* %3
br label %29
29: ; preds = %11, %8
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: bs_load_img <rotation> <image.pgm>\0A\0D\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %23
7: ; preds = %2
%8 = tail call i32 (...) @bs_chip_init()
%9 = tail call i32 (...) @bs_cmd_flag_hif_mode_cmd()
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 @bs_cmd_set_rotmode(i32 %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @bs_cmd_ld_img_pgm(i32 3, i8* %15)
%17 = tail call i32 @bs_cmd_wait_for_bit(i32 824, i32 0, i32 0)
%18 = tail call i32 @bs_cmd_wait_for_bit(i32 824, i32 3, i32 0)
%19 = tail call i32 @bs_cmd_upd_full(i32 3, i32 15, i32 0)
%20 = tail call i32 @bs_cmd_wait_for_bit(i32 824, i32 0, i32 0)
%21 = tail call i32 @bs_cmd_wait_for_bit(i32 824, i32 3, i32 0)
%22 = tail call i32 (...) @bs_chip_final()
br label %23
23: ; preds = %7, %4
%24 = phi i32 [ -1, %4 ], [ 0, %7 ]
ret i32 %24
}