#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 const *, char *);
int /*<<< orphan*/ fwrite(unsigned char const *, int, int const,
                          int /*<<< orphan*/ *);
void data_to_file_raw(const unsigned char *data, const int data_size,
                      const char *filename) {
  FILE *data_file = fopen(filename, "w");
  fclose(data_file);
  data_file = fopen(filename, "a");
  fwrite(data, 1, data_size, data_file);
  fclose(data_file);
}


x86 assembly (clang, -O0):
<data_to_file_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_to_file_raw>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xebc(%rip),%rsi
mov    %rdx,%rdi
call   1040 <fopen@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
define void @data_to_file_raw(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = call i32 @fclose(i32* %10)
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = load i32*, i32** %7
%17 = call i32 @fwrite(i8* %14, i32 1, i32 %15, i32* %16)
%18 = load i32*, i32** %7
%19 = call i32 @fclose(i32* %18)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
define void @data_to_file_raw(i8* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @fclose(i32* %4)
%6 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @fwrite(i8* %0, i32 1, i32 %1, i32* %6)
%8 = tail call i32 @fclose(i32* %6)
ret void
}