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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char,
                           unsigned char, unsigned char, unsigned char,
                           unsigned char, unsigned char, unsigned char,
                           unsigned char, unsigned char);
int reset_camera();
int image_size(unsigned char XX) {
  int result = -1;
  unsigned char buf[5];
  unsigned char ratio[9] = {0x56, 0x00, 0x31, 0x05, 0x04, 0x01, 0x00, 0x19, XX};
  FILE *camera = fopen("/dev/ttyMFD1", "a+");
  fprintf(camera, "%c%c%c%c%c%c%c%c%c", ratio[0], ratio[1], ratio[2], ratio[3],
          ratio[4], ratio[5], ratio[6], ratio[7], ratio[8]);
  fgets(buf, 5, camera);
  if (buf[0] == 0x76 && buf[2] == 0x31)
    result = 0;
  fclose(camera);
  result = result + reset_camera();
  return result;
}


x86 assembly (clang, -O0):
<image_size>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movb   $0x56,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
movb   $0x31,-0x1c(%rbp)
movb   $0x5,-0x1b(%rbp)
movb   $0x4,-0x1a(%rbp)
movb   $0x1,-0x19(%rbp)
movb   $0x0,-0x18(%rbp)
movb   $0x19,-0x17(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x16(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1e(%rbp),%dl
mov    -0x1d(%rbp),%cl
mov    -0x1c(%rbp),%r8b
mov    -0x1b(%rbp),%r9b
mov    -0x1a(%rbp),%bl
mov    -0x19(%rbp),%r11b
mov    -0x18(%rbp),%r10b
mov    -0x17(%rbp),%al
lea    0xe46(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %bl,%ebx
mov    %ebx,(%rsp)
movzbl %r11b,%r11d
mov    %r11d,0x8(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x10(%rsp)
movzbl %al,%eax
mov    %eax,0x18(%rsp)
movzbl -0x16(%rbp),%eax
mov    %eax,0x20(%rsp)
call   1050 <fprintf@plt>
lea    -0x15(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x5,%esi
call   1040 <fgets@plt>
movzbl -0x15(%rbp),%eax
cmp    $0x76,%eax
jne    1237 <image_size+0xe7>
movzbl -0x13(%rbp),%eax
cmp    $0x31,%eax
jne    1237 <image_size+0xe7>
movl   $0x0,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <reset_camera@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<image_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xe94(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x31,%r8d
mov    $0x5,%r9d
push   %r14
push   $0x19
push   $0x0
push   $0x1
push   $0x4
call   1050 <fprintf@plt>
add    $0x30,%rsp
lea    0xb(%rsp),%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0xb(%rsp),%al
mov    0xd(%rsp),%cl
xor    $0x76,%al
xor    $0x31,%cl
xor    %ebp,%ebp
or     %al,%cl
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1060 <reset_camera@plt>
sub    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyMFD1\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [19 x i8] c"%c%c%c%c%c%c%c%c%c\00"
define i32 @image_size(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [5 x i8]
%5 = alloca [9 x i8]
%6 = alloca i32*
store i8 %0, i8* %2
store i32 -1, i32* %3
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
store i8 86, i8* %7
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 49, i8* %9
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 5, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 4, i8* %11
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8 1, i8* %12
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 25, i8* %14
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %2
store i8 %16, i8* %15
%17 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%20 = load i8, i8* %19
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 1
%22 = load i8, i8* %21
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 2
%24 = load i8, i8* %23
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 3
%26 = load i8, i8* %25
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 4
%28 = load i8, i8* %27
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 5
%30 = load i8, i8* %29
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 6
%32 = load i8, i8* %31
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 7
%34 = load i8, i8* %33
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 8
%36 = load i8, i8* %35
%37 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %20, i8 zeroext %22, i8 zeroext %24, i8 zeroext %26, i8 zeroext %28, i8 zeroext %30, i8 zeroext %32, i8 zeroext %34, i8 zeroext %36)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32 @fgets(i8* %38, i32 5, i32* %39)
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 118
br i1 %44, label %45, label %51
45: ; preds = %1
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 49
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 0, i32* %3
br label %51
51: ; preds = %50, %45, %1
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* %3
%55 = call i32 (...) @reset_camera()
%56 = add nsw i32 %54, %55
store i32 %56, i32* %3
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyMFD1\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [19 x i8] c"%c%c%c%c%c%c%c%c%c\00"
define i32 @image_size(i8 zeroext %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8 zeroext 86, i8 zeroext 0, i8 zeroext 49, i8 zeroext 5, i8 zeroext 4, i8 zeroext 1, i8 zeroext 0, i8 zeroext 25, i8 zeroext %0)
%6 = call i32 @fgets(i8* %3, i32 5, i32* %4)
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 118
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 49
%12 = select i1 %8, i1 true, i1 %11
%13 = sext i1 %12 to i32
%14 = call i32 @fclose(i32* %4)
%15 = call i32 (...) @reset_camera()
%16 = add nsw i32 %15, %13
ret i32 %16
}