#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 */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void fputcontent(const char *filename, const char *content) {
  FILE *fileh = fopen(filename, "wb");
  if (NULL == fileh) {
    perror("Cannot create file");
    exit(EXIT_FAILURE);
  }
  if (EOF == fputs(content, fileh)) {
    perror("Cannot write to file");
    exit(EXIT_FAILURE);
  }
  fclose(fileh);
}


x86 assembly (clang, -O0):
<fputcontent>:
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   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    119a <fputcontent+0x4a>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    11df <fputcontent+0x8f>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputcontent>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1193 <fputcontent+0x43>
mov    %rax,%rbx
mov    0x2e75(%rip),%rax
mov    (%rax),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
cmp    %rax,%r15
je     119c <fputcontent+0x4c>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xe69(%rip),%rdi
jmp    11a3 <fputcontent+0x53>
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@EXIT_FAILURE = global i32 0
@EOF = global i64 0
@.str.2 = [21 x i8] c"Cannot write to file\00"
define void @fputcontent(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* null, %8
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i64, i64* @EOF
%16 = load i8*, i8** %4
%17 = load i32*, i32** %5
%18 = call i64 @fputs(i8* %16, i32* %17)
%19 = icmp eq i64 %15, %18
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@EXIT_FAILURE = global i32 0
@EOF = global i64 0
@.str.2 = [21 x i8] c"Cannot write to file\00"
define void @fputcontent(i8* nocapture %0, i8* nocapture %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 %9
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = load i64, i64* @EOF
%11 = tail call i64 @fputs(i8* %1, i32* %3)
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = tail call i32 @fclose(i32* %3)
ret void
}