#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*/ fputc(char const, int /*<<< orphan*/ *);
int strlen(char const *);
void make_file(const char *filename, const char *text) {
  char c;
  int i;
  FILE *file;
  file = fopen(filename, "w");
  for (i = 0; i < strlen(text); i++) {
    fputc(text[i], file);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<make_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11ac <make_file+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <make_file+0x2b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1190 <make_file+0x50>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1170 <make_file+0x30>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
define void @make_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
store i32 0, i32* %6
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %6
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i32*, i32** %7
%22 = call i32 @fputc(i8 signext %20, i32* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %10
26: ; preds = %10
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define void @make_file(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2, %6
%7 = phi i64 [ %11, %6 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = tail call i32 @fputc(i8 signext %9, i32* %3)
%11 = add nuw nsw i64 %7, 1
%12 = tail call i32 @strlen(i8* %1)
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %11, %13
br i1 %14, label %6, label %15
15: ; preds = %6, %2
%16 = tail call i32 @fclose(i32* %3)
ret void
}