#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*/ *);
void makefile(char *array, char *temp) {
  FILE *fp;
  char ch;
  int i = 0;
  fp = fopen(temp, "w");
  while (1) {
    ch = array[i++];
    if (ch == '\0')
      break;
    fputc(ch, fp);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<makefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1185 <makefile+0x55>
jmp    1199 <makefile+0x69>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    115b <makefile+0x2b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makefile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     1176 <makefile+0x46>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <makefile+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>

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

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