#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);
int read_size(unsigned char *XH, unsigned char *XL) {
  int result = -1;
  unsigned char buf[10];
  unsigned char size[5] = {0x56, 0x00, 0x34, 0x01, 0x00};
  FILE *camera = fopen("/dev/ttyMFD1", "a+");
  fprintf(camera, "%c%c%c%c%c", size[0], size[1], size[2], size[3], size[4]);
  fgets(buf, 10, camera);
  if (buf[0] == 0x76 && buf[2] == 0x34)
    result = 0;
  *XH = buf[7];
  *XL = buf[8];
  fclose(camera);
  return result;
}


x86 assembly (clang, -O0):
<read_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    0xea3(%rip),%eax
mov    %eax,-0x23(%rbp)
mov    0xe9e(%rip),%al
mov    %al,-0x1f(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x23(%rbp),%dl
mov    -0x22(%rbp),%cl
mov    -0x21(%rbp),%r8b
mov    -0x20(%rbp),%al
lea    0xe7d(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %al,%r9d
movzbl -0x1f(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <fprintf@plt>
lea    -0x1e(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0xa,%esi
call   1040 <fgets@plt>
movzbl -0x1e(%rbp),%eax
cmp    $0x76,%eax
jne    11e5 <read_size+0xa5>
movzbl -0x1c(%rbp),%eax
cmp    $0x34,%eax
jne    11e5 <read_size+0xa5>
movl   $0x0,-0x14(%rbp)
mov    -0x17(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x16(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea9(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,(%rsp)
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x34,%r8d
mov    $0x1,%r9d
call   1050 <fprintf@plt>
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0xe(%rsp),%al
mov    0x10(%rsp),%cl
xor    $0x76,%al
xor    $0x34,%cl
xor    %ebp,%ebp
or     %al,%cl
setne  %bpl
neg    %ebp
mov    0x15(%rsp),%al
mov    %al,(%r15)
mov    0x16(%rsp),%al
mov    %al,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.read_size.size = [5 x i8] c"V\004\01\00"
@.str = [13 x i8] c"/dev/ttyMFD1\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [11 x i8] c"%c%c%c%c%c\00"
define i32 @read_size(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca [5 x i8]
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
%9 = bitcast [5 x i8]* %7 to i8*
%10 = 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* %10, i32** %8
%11 = load i32*, i32** %8
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%13 = load i8, i8* %12
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 1
%15 = load i8, i8* %14
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
%17 = load i8, i8* %16
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 3
%19 = load i8, i8* %18
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
%21 = load i8, i8* %20
%22 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %13, i8 zeroext %15, i8 zeroext %17, i8 zeroext %19, i8 zeroext %21)
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %8
%25 = call i32 @fgets(i8* %23, i32 10, i32* %24)
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 118
br i1 %29, label %30, label %36
30: ; preds = %2
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 2
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %33, 52
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 0, i32* %5
br label %36
36: ; preds = %35, %30, %2
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 7
%38 = load i8, i8* %37
%39 = load i8*, i8** %3
store i8 %38, i8* %39
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 8
%41 = load i8, i8* %40
%42 = load i8*, i8** %4
store i8 %41, i8* %42
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyMFD1\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [11 x i8] c"%c%c%c%c%c\00"
define i32 @read_size(i8* nocapture writeonly %0, i8* nocapture writeonly %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = 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))
%6 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 zeroext 86, i8 zeroext 0, i8 zeroext 52, i8 zeroext 1, i8 zeroext 0)
%7 = call i32 @fgets(i8* %4, i32 10, i32* %5)
%8 = load i8, i8* %4
%9 = icmp ne i8 %8, 118
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 52
%13 = select i1 %9, i1 true, i1 %12
%14 = sext i1 %13 to i32
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
%16 = load i8, i8* %15
store i8 %16, i8* %0
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 8
%18 = load i8, i8* %17
store i8 %18, i8* %1
%19 = call i32 @fclose(i32* %5)
ret i32 %14
}