#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ *create_dir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ std_err();
void write_output_file(char *file_output, uint32_t pos, char *buffer,
                       uint32_t size) {
  FILE *pFile;
  uint8_t *tmp = create_dir((uint8_t *)file_output);
  printf("- Open output file:    %s\n", file_output);
  pFile = fopen(file_output, "wb");
  if (!pFile)
    std_err();
  if (pos)
    fseek(pFile, pos, SEEK_SET);
  fwrite(buffer, 1, size, pFile);
  fclose(pFile);
}


x86 assembly (clang, -O0):
<write_output_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <create_dir@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c9 <write_output_file+0x59>
mov    $0x0,%al
call   1090 <std_err@plt>
cmpl   $0x0,-0xc(%rbp)
je     11e8 <write_output_file+0x78>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_output_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <create_dir@plt>
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e9 <write_output_file+0x79>
test   %ebp,%ebp
je     11c4 <write_output_file+0x54>
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
xor    %eax,%eax
call   1090 <std_err@plt>
test   %ebp,%ebp
jne    11b1 <write_output_file+0x41>
jmp    11c4 <write_output_file+0x54>

LLVM IR (-O0):
@.str = [27 x i8] c"- Open output file: %s\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
define void @write_output_file(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to i32*
%13 = call i32* @create_dir(i32* %12)
store i32* %13, i32** %10
%14 = load i8*, i8** %5
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %4
%21 = call i32 (...) @std_err()
br label %22
22: ; preds = %20, %4
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32*, i32** %9
%27 = load i32, i32* %6
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %26, i32 %27, i32 %28)
br label %30
30: ; preds = %25, %22
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = load i32*, i32** %9
%34 = call i32 @fwrite(i8* %31, i32 1, i32 %32, i32* %33)
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"- Open output file: %s\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
define void @write_output_file(i8* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = bitcast i8* %0 to i32*
%6 = tail call i32* @create_dir(i32* %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 (...) @std_err()
br label %12
12: ; preds = %10, %4
%13 = icmp eq i32 %1, 0
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %8, i32 %1, i32 %15)
br label %17
17: ; preds = %14, %12
%18 = tail call i32 @fwrite(i8* %2, i32 1, i32 %3, i32* %8)
%19 = tail call i32 @fclose(i32* %8)
ret void
}