#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 compression_ratio(unsigned char XX) {
  int result = -1;
  unsigned char buf[6];
  unsigned char ratio[9] = {0x56, 0x00, 0x31, 0x05, 0x01, 0x01, 0x12, 0x04, 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, 6, camera);
  if (buf[0] == 0x76 && buf[2] == 0x31 && buf[5] == XX)
    result = 0;
  fclose(camera);
  return result;
}


x86 assembly (clang, -O0):
<compression_ratio>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movb   $0x56,-0x1f(%rbp)
movb   $0x0,-0x1e(%rbp)
movb   $0x31,-0x1d(%rbp)
movb   $0x5,-0x1c(%rbp)
movb   $0x1,-0x1b(%rbp)
movb   $0x1,-0x1a(%rbp)
movb   $0x12,-0x19(%rbp)
movb   $0x4,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x17(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1f(%rbp),%dl
mov    -0x1e(%rbp),%cl
mov    -0x1d(%rbp),%r8b
mov    -0x1c(%rbp),%r9b
mov    -0x1b(%rbp),%bl
mov    -0x1a(%rbp),%r11b
mov    -0x19(%rbp),%r10b
mov    -0x18(%rbp),%al
lea    0xe56(%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 -0x17(%rbp),%eax
mov    %eax,0x20(%rsp)
call   1050 <fprintf@plt>
lea    -0x16(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x6,%esi
call   1040 <fgets@plt>
movzbl -0x16(%rbp),%eax
cmp    $0x76,%eax
jne    1237 <compression_ratio+0xf7>
movzbl -0x14(%rbp),%eax
cmp    $0x31,%eax
jne    1237 <compression_ratio+0xf7>
movzbl -0x11(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1237 <compression_ratio+0xf7>
movl   $0x0,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<compression_ratio>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xeae(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x31,%r8d
mov    $0x5,%r9d
push   %r14
push   $0x4
push   $0x12
push   $0x1
push   $0x1
call   1050 <fprintf@plt>
add    $0x30,%rsp
lea    0xa(%rsp),%rdi
mov    $0x6,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0xa(%rsp),%al
mov    0xc(%rsp),%cl
xor    $0x76,%al
xor    $0x31,%cl
or     %al,%cl
mov    0xf(%rsp),%al
xor    %r14b,%al
xor    %ebp,%ebp
or     %cl,%al
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %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 @compression_ratio(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [6 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 1, 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 18, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 4, 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 [6 x i8], [6 x i8]* %4, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32 @fgets(i8* %38, i32 6, i32* %39)
%41 = getelementptr inbounds [6 x i8], [6 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 %58
45: ; preds = %1
%46 = getelementptr inbounds [6 x i8], [6 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 %58
50: ; preds = %45
%51 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = load i8, i8* %2
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %53, %55
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 0, i32* %3
br label %58
58: ; preds = %57, %50, %45, %1
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %3
ret i32 %61
}

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 @compression_ratio(i8 zeroext %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 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 1, i8 zeroext 1, i8 zeroext 18, i8 zeroext 4, i8 zeroext %0)
%6 = call i32 @fgets(i8* %3, i32 6, i32* %4)
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 118
%9 = getelementptr inbounds [6 x i8], [6 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 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, %0
%16 = select i1 %12, i1 true, i1 %15
%17 = sext i1 %16 to i32
%18 = call i32 @fclose(i32* %4)
ret i32 %17
}