#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int write_to_tracefile(char *file, char *value) {
  FILE *f;
  char path[256];
  snprintf(path, 256, "%s%s", "/sys/kernel/debug/tracing/", file);
  f = fopen(path, "w");
  if (f == NULL) {
    perror("fopen tracefile");
    return 1;
  }
  fprintf(f, "%s", value);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<write_to_tracefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe86(%rip),%rdx
lea    0xe84(%rip),%rcx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <write_to_tracefile+0x70>
lea    0xe73(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <write_to_tracefile+0x94>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_tracefile>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r8
lea    0xe99(%rip),%rdx
lea    0xe97(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b5 <write_to_tracefile+0x65>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe66(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11aa <write_to_tracefile+0x5a>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [27 x i8] c"/sys/kernel/debug/tracing/\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [16 x i8] c"fopen tracefile\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @write_to_tracefile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [256 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %23
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = load i8*, i8** %5
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %17, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [27 x i8] c"/sys/kernel/debug/tracing/\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [16 x i8] c"fopen tracefile\00"
define i32 @write_to_tracefile(i8* %0, i8* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %13
10: ; preds = %2
%11 = call i32 @fputs(i8* %1, i32* %6)
%12 = call i32 @fclose(i32* %6)
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ 1, %8 ], [ 0, %10 ]
ret i32 %14
}