#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
char *tracecmd_get_tracing_file(char const *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void write_file(const char *name, char *val) {
  char *path;
  int fd;
  ssize_t n;
  path = tracecmd_get_tracing_file(name);
  fd = open(path, O_WRONLY);
  if (fd < 0)
    die("writing %s", path);
  n = write(fd, val, strlen(val));
  if (n < 0)
    die("failed to write '%d' to %s\n", path);
  tracecmd_put_tracing_file(path);
  close(fd);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bc <write_file+0x4c>
mov    -0x18(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1090 <die@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1200 <write_file+0x90>
mov    -0x18(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1090 <die@plt>
mov    -0x18(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11a5 <write_file+0x35>
lea    0xe63(%rip),%rdi
mov    %rbx,%rsi
call   1090 <die@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    11cd <write_file+0x5d>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
call   1090 <die@plt>
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <close@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [11 x i8] c"writing %s\00"
@.str.1 = [28 x i8] c"failed to write '%d' to %s\0A\00"
define void @write_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @tracecmd_get_tracing_file(i8* %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %2
%19 = load i32, i32* %6
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = call i64 @write(i32 %19, i8* %20, i32 %22)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %18
%30 = load i8*, i8** %5
%31 = call i32 @tracecmd_put_tracing_file(i8* %30)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [11 x i8] c"writing %s\00"
@.str.1 = [28 x i8] c"failed to write '%d' to %s\0A\00"
define void @write_file(i8* %0, i8* %1) {
%3 = tail call i8* @tracecmd_get_tracing_file(i8* %0)
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* %3, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %9
9: ; preds = %7, %2
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i64 @write(i32 %5, i8* %1, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %15
15: ; preds = %13, %9
%16 = tail call i32 @tracecmd_put_tracing_file(i8* %3)
%17 = tail call i32 @close(i32 %5)
ret void
}