#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);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int reset_camera() {
  int result = -1;
  char buf[4];
  unsigned char reset[4] = {0x56, 0x00, 0x26, 0x00};
  FILE *camera = fopen("/dev/ttyMFD1", "a+");
  fprintf(camera, "%c%c%c%c", reset[0], reset[1], reset[2], reset[3]);
  fgets(buf, 4, camera);
  if (buf[0] == 0x76 && buf[2] == 0x26)
    result = 0;
  fclose(camera);
  sleep(2);
  system("stty -F /dev/ttyMFD1 38400");
  return result;
}


x86 assembly (clang, -O0):
<reset_camera>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0xe8b(%rip),%eax
mov    %eax,-0xc(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%dl
mov    -0xb(%rbp),%cl
mov    -0xa(%rbp),%al
lea    0xe71(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
movzbl -0x9(%rbp),%r9d
call   1060 <fprintf@plt>
lea    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4,%esi
call   1050 <fgets@plt>
movsbl -0x8(%rbp),%eax
cmp    $0x76,%eax
jne    11ea <reset_camera+0x8a>
movsbl -0x6(%rbp),%eax
cmp    $0x26,%eax
jne    11ea <reset_camera+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x2,%edi
call   1080 <sleep@plt>
lea    0xe19(%rip),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_camera>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe90(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x26,%r8d
xor    %r9d,%r9d
call   1060 <fprintf@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    0x4(%rsp),%al
mov    0x6(%rsp),%cl
xor    $0x76,%al
xor    $0x26,%cl
xor    %ebp,%ebp
or     %al,%cl
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x2,%edi
call   1080 <sleep@plt>
lea    0xe3f(%rip),%rdi
call   1040 <system@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.reset_camera.reset = [4 x i8] c"V\00&\00"
@.str = [13 x i8] c"/dev/ttyMFD1\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [9 x i8] c"%c%c%c%c\00"
@.str.3 = [27 x i8] c"stty -F /dev/ttyMFD1 38400\00"
define i32 @reset_camera() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [4 x i8]
%4 = alloca i32*
store i32 -1, i32* %1
%5 = bitcast [4 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 [4 x i8], [4 x i8]* %3, i64 0, i64 0
%9 = load i8, i8* %8
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%11 = load i8, i8* %10
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%13 = load i8, i8* %12
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%15 = load i8, i8* %14
%16 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %9, i8 zeroext %11, i8 zeroext %13, i8 zeroext %15)
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i32 @fgets(i8* %17, i32 4, i32* %18)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 118
br i1 %23, label %24, label %30
24: ; preds = %0
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 38
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %1
br label %30
30: ; preds = %29, %24, %0
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
%33 = call i32 @sleep(i32 2)
%34 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%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 = [9 x i8] c"%c%c%c%c\00"
@.str.3 = [27 x i8] c"stty -F /dev/ttyMFD1 38400\00"
define i32 @reset_camera() {
%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 ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8 zeroext 86, i8 zeroext 0, i8 zeroext 38, 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, 38
%11 = select i1 %7, i1 true, i1 %10
%12 = sext i1 %11 to i32
%13 = call i32 @fclose(i32* %3)
%14 = call i32 @sleep(i32 2)
%15 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
ret i32 %12
}