#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(char *, int, int /*<<< orphan*/, void *);
int /*<<< orphan*/ basm_initvfs();
int /*<<< orphan*/ strlen(char *);
int basm_storetextfile(char *name, char *buf) {
  void *fd;
  char *s;
  basm_initvfs();
  fd = basm_fopen(name, "wt");
  if (!fd)
    return (-1);
  basm_fwrite(buf, 1, strlen(buf), fd);
  basm_fclose(fd);
  return (0);
}


x86 assembly (clang, -O0):
<basm_storetextfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <basm_initvfs@plt>
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <basm_fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1192 <basm_storetextfile+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <basm_storetextfile+0x77>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <basm_fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1060 <basm_fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basm_storetextfile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <basm_initvfs@plt>
lea    0xe95(%rip),%rsi
mov    %rbp,%rdi
call   1040 <basm_fopen@plt>
test   %rax,%rax
je     119f <basm_storetextfile+0x4f>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   1070 <basm_fwrite@plt>
mov    %rbp,%rdi
call   1060 <basm_fclose@plt>
jmp    11a5 <basm_storetextfile+0x55>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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