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


x86 assembly (clang, -O0):
<take_picture>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xea6(%rip),%al
mov    %al,-0x9(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xd(%rbp),%dl
mov    -0xc(%rbp),%cl
mov    -0xb(%rbp),%r8b
mov    -0xa(%rbp),%al
lea    0xe85(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %al,%r9d
movzbl -0x9(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <fprintf@plt>
lea    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4,%esi
call   1040 <fgets@plt>
movsbl -0x8(%rbp),%eax
cmp    $0x76,%eax
jne    11dd <take_picture+0x9d>
movsbl -0x6(%rbp),%eax
cmp    $0x36,%eax
jne    11dd <take_picture+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<take_picture>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xeb3(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,(%rsp)
lea    0xea6(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x36,%r8d
mov    $0x1,%r9d
call   1050 <fprintf@plt>
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0x14(%rsp),%al
mov    0x16(%rsp),%cl
xor    $0x76,%al
xor    $0x36,%cl
xor    %ebp,%ebp
or     %al,%cl
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.take_picture.take = [5 x i8] c"V\006\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 @take_picture() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32*
store i32 -1, i32* %1
%5 = bitcast [5 x i8]* %3 to i8*
%6 = 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* %6, i32** %4
%7 = load i32*, i32** %4
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = load i8, i8* %8
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
%11 = load i8, i8* %10
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%13 = load i8, i8* %12
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
%15 = load i8, i8* %14
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
%17 = load i8, i8* %16
%18 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %9, i8 zeroext %11, i8 zeroext %13, i8 zeroext %15, i8 zeroext %17)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32 @fgets(i8* %19, i32 4, i32* %20)
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 118
br i1 %25, label %26, label %32
26: ; preds = %0
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 54
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 0, i32* %1
br label %32
32: ; preds = %31, %26, %0
%33 = load i32*, i32** %4
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %1
ret i32 %35
}

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 @take_picture() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 zeroext 86, i8 zeroext 0, i8 zeroext 54, i8 zeroext 1, i8 zeroext 0)
%5 = call i32 @fgets(i8* %2, i32 4, i32* %3)
%6 = load i8, i8* %2
%7 = icmp ne i8 %6, 118
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 54
%11 = select i1 %7, i1 true, i1 %10
%12 = sext i1 %11 to i32
%13 = call i32 @fclose(i32* %3)
ret i32 %12
}