#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int write_trace_marker(char *marker, int size) {
  int ret;
  FILE *file;
  file = fopen("/sys/kernel/debug/tracing/trace_marker", "w");
  if (file == NULL) {
    return -errno;
  }
  ret = fwrite(marker, sizeof(char), size, file);
  fclose(file);
  return ret;
}


x86 assembly (clang, -O0):
<write_trace_marker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1174 <write_trace_marker+0x44>
xor    %eax,%eax
mov    0x2e76(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <write_trace_marker+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_trace_marker>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xebf(%rip),%rdi
lea    0xedf(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1176 <write_trace_marker+0x46>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    1181 <write_trace_marker+0x51>
mov    0x2e63(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [39 x i8] c"/sys/kernel/debug/tracing/trace_marker\00"
@.str.1 = [2 x i8] c"w\00"
@errno = global i32 0
define i32 @write_trace_marker(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = sub nsw i32 0, %6
br label %11
8: ; preds = %2
%9 = tail call i32 @fwrite(i8* %0, i32 1, i32 %1, i32* %3)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ %7, %5 ], [ %9, %8 ]
ret i32 %12
}