#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(char const *, int, unsigned int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ lace_log_errorf(char *, char const *);
unsigned int strlen(char const *);
void write_here_doc_file(const char *name, const char *doc) {
  unsigned n;
  FILE *out;
  out = fopen(name, "wb");
  if (!out) {
    lace_log_errorf("Cannot open file for writing!: %s", name);
    return;
  }
  n = strlen(doc);
  fwrite(doc, sizeof(char), n, out);
  fclose(out);
}


x86 assembly (clang, -O0):
<write_here_doc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <write_here_doc_file+0x44>
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <lace_log_errorf@plt>
jmp    11be <write_here_doc_file+0x6e>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_here_doc_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1196 <write_here_doc_file+0x46>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe66(%rip),%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <lace_log_errorf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [34 x i8] c"Cannot open file for writing!: %s\00"
define void @write_here_doc_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @lace_log_errorf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %23
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = load i32*, i32** %6
%20 = call i32 @fwrite(i8* %17, i32 1, i32 %18, i32* %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %14, %11
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [34 x i8] c"Cannot open file for writing!: %s\00"
define void @write_here_doc_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @lace_log_errorf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 @fwrite(i8* %1, i32 1, i32 %8, i32* %3)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %7, %5
ret void
}