#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*/ trigger_buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
void toggle_trigger(char *path_triggerfile, int bool_start) {
  FILE *triggerfile;
  char trigger_buffer[] = {0x00, 0x00, 0x00, 0x00};
  if (bool_start == 1)
    trigger_buffer[3] = 0x01;
  triggerfile = fopen(path_triggerfile, "wb");
  if (triggerfile < 0)
    error("ERROR opening trigger file");
  if (fwrite(trigger_buffer, sizeof(char), sizeof(trigger_buffer),
             triggerfile) != sizeof(trigger_buffer))
    error("ERROR writing to trigger file");
  fclose(triggerfile);
}


x86 assembly (clang, -O0):
<toggle_trigger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
cmpl   $0x1,-0xc(%rbp)
jne    117d <toggle_trigger+0x2d>
movb   $0x1,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    11a8 <toggle_trigger+0x58>
lea    0xe60(%rip),%rdi
call   1050 <error@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1070 <fwrite@plt>
cltq
cmp    $0x4,%rax
je     11d7 <toggle_trigger+0x87>
lea    0xe4c(%rip),%rdi
call   1050 <error@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggle_trigger>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
cmp    $0x1,%esi
jne    1157 <toggle_trigger+0x17>
movb   $0x1,0xf(%rsp)
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
cmp    $0x4,%eax
je     118e <toggle_trigger+0x4e>
lea    0xe7a(%rip),%rdi
call   1040 <error@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [27 x i8] c"ERROR opening trigger file\00"
@.str.2 = [30 x i8] c"ERROR writing to trigger file\00"
define void @toggle_trigger(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [4 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = bitcast [4 x i8]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 1, i8* %11
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ult i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i32 @fwrite(i8* %20, i32 1, i32 4, i32* %21)
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %23, 4
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.2 = [30 x i8] c"ERROR writing to trigger file\00"
define void @toggle_trigger(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i32 %1, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = bitcast i32* %3 to [4 x i8]*
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
store i8 1, i8* %8
br label %9
9: ; preds = %6, %2
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @fwrite(i8* %4, i32 1, i32 4, i32* %10)
%12 = icmp eq i32 %11, 4
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = tail call i32 @fclose(i32* %10)
ret void
}