#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 */

/* Variables and functions */
int /*<<< orphan*/ basm_fclose(void *);
void *basm_fopen(char *, char *);
int /*<<< orphan*/ basm_fwrite(void *, int, int, void *);
int /*<<< orphan*/ basm_initvfs();
int basm_storefile(char *name, void *buf, int sz) {
  void *fd;
  basm_initvfs();
  fd = basm_fopen(name, "wb");
  if (!fd)
    return (-1);
  basm_fwrite(buf, 1, sz, fd);
  basm_fclose(fd);
  return (0);
}


x86 assembly (clang, -O0):
<basm_storefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <basm_initvfs@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <basm_fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1185 <basm_storefile+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <basm_storefile+0x6a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <basm_fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1050 <basm_fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basm_storefile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <basm_initvfs@plt>
lea    0xea0(%rip),%rsi
mov    %rbp,%rdi
call   1030 <basm_fopen@plt>
test   %rax,%rax
je     118d <basm_storefile+0x4d>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1060 <basm_fwrite@plt>
mov    %rbp,%rdi
call   1050 <basm_fclose@plt>
jmp    1192 <basm_storefile+0x52>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @basm_storefile(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = call i32 (...) @basm_initvfs()
%10 = load i8*, i8** %5
%11 = call i8* @basm_fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 -1, i32* %4
br label %22
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = load i8*, i8** %8
%19 = call i32 @basm_fwrite(i8* %16, i32 1, i32 %17, i8* %18)
%20 = load i8*, i8** %8
%21 = call i32 @basm_fclose(i8* %20)
store i32 0, i32* %4
br label %22
22: ; preds = %15, %14
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @basm_storefile(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 (...) @basm_initvfs()
%5 = tail call i8* @basm_fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @basm_fwrite(i8* %1, i32 1, i32 %2, i8* %5)
%9 = tail call i32 @basm_fclose(i8* %5)
br label %10
10: ; preds = %3, %7
%11 = phi i32 [ 0, %7 ], [ -1, %3 ]
ret i32 %11
}