#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*/ *fopen(char *, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
FILE *writeFile(char *filename, void *data, long bytes) {
  FILE *out = tmpfile();
  int i;
  out = fopen(filename, "wb");
  fwrite(data, 1, bytes, out);
  freopen(filename, "rb", out);
  return out;
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1030 <freopen@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <tmpfile@plt>
lea    0xea1(%rip),%rsi
mov    %r12,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
lea    0xe7f(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
call   1030 <freopen@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [3 x i8] c"rb\00"
define i32* @writeFile(i8* %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32* (...) @tmpfile()
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @fwrite(i8* %1, i32 1, i64 %2, i32* %5)
%7 = tail call i32 @freopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
ret i32* %5
}