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


x86 assembly (clang, -O0):
<exit_power_saving>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xea5(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xe9d(%rip),%al
mov    %al,-0xa(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%dl
mov    -0xf(%rbp),%cl
mov    -0xe(%rbp),%r8b
mov    -0xd(%rbp),%r9b
mov    -0xc(%rbp),%r10b
mov    -0xb(%rbp),%al
lea    0xe74(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl %r10b,%r10d
mov    %r10d,(%rsp)
movzbl %al,%eax
mov    %eax,0x8(%rsp)
movzbl -0xa(%rbp),%eax
mov    %eax,0x10(%rsp)
call   1050 <fprintf@plt>
lea    -0x9(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x5,%esi
call   1040 <fgets@plt>
movzbl -0x9(%rbp),%eax
cmp    $0x76,%eax
jne    1200 <exit_power_saving+0xc0>
movzbl -0x7(%rbp),%eax
cmp    $0x3e,%eax
jne    1200 <exit_power_saving+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exit_power_saving>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xeac(%rip),%rsi
mov    %rax,%rdi
mov    $0x56,%edx
xor    %ecx,%ecx
mov    $0x3e,%r8d
mov    $0x3,%r9d
push   $0x0
push   $0x1
push   $0x0
call   1050 <fprintf@plt>
add    $0x20,%rsp
lea    0x3(%rsp),%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0x3(%rsp),%al
mov    0x5(%rsp),%cl
xor    $0x76,%al
xor    $0x3e,%cl
xor    %ebp,%ebp
or     %al,%cl
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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