#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 *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
long strlen(char *);
int _dcontent_to_file(char *filename, char *content) {
  FILE *file = fopen(filename, "wb");
  long content_len = strlen(content);
  if (file != NULL) {
    for (int i = 0; i < content_len; i++) {
      fputc(content[i], file);
    }
    fclose(file);
    return 1;
  } else {
    printf("Unable to write: %s.\n", filename);
    return 0;
  }
}


x86 assembly (clang, -O0):
<_dcontent_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11db <_dcontent_to_file+0x8b>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    11c6 <_dcontent_to_file+0x76>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1193 <_dcontent_to_file+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <_dcontent_to_file+0xa2>
mov    -0x10(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dcontent_to_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %r15,%r15
je     11b5 <_dcontent_to_file+0x65>
mov    %rax,%r13
test   %rax,%rax
jle    11a6 <_dcontent_to_file+0x56>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r14,%rbx,1),%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <_dcontent_to_file+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11c6 <_dcontent_to_file+0x76>
lea    0xe47(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [22 x i8] c"Unable to write: %s.\0A\00"
define i32 @_dcontent_to_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %35
15: ; preds = %2
store i32 0, i32* %8
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = load i64, i64* %7
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = load i32*, i32** %6
%28 = call i32 @fputc(i8 signext %26, i32* %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %16
32: ; preds = %16
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
store i32 1, i32* %3
br label %38
35: ; preds = %2
%36 = load i8*, i8** %4
%37 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %32
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [22 x i8] c"Unable to write: %s.\0A\00"
define i32 @_dcontent_to_file(i8* %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 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp eq i32* %3, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = icmp sgt i64 %4, 0
br i1 %7, label %10, label %8
8: ; preds = %10, %6
%9 = tail call i32 @fclose(i32* %3)
br label %19
10: ; preds = %6, %10
%11 = phi i64 [ %15, %10 ], [ 0, %6 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @fputc(i8 signext %13, i32* %3)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %4
br i1 %16, label %8, label %10
17: ; preds = %2
%18 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %8
%20 = phi i32 [ 1, %8 ], [ 0, %17 ]
ret i32 %20
}