#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*/ fprintf(int /*<<< orphan*/ *, char *, int, char const *);
int /*<<< orphan*/ printf(char *, ...);
int make_file(const char *pfile) {
  if (NULL == pfile) {
    printf("pfile is NULL\n");
    return -1;
  }
  FILE *fp = fopen(pfile, "w");
  if (NULL == fp) {
    printf("open file [%s] faild\n", pfile);
    return 1;
  }
  const char *px = "abcdefg hijklmn opqrst uvwxyz. hello, world !\n";
  int i = 0;
  for (i = 0; i < 100; i++) {
    fprintf(fp, "[%02d] %s", i, px);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<make_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1172 <make_file+0x32>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <make_file+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11b0 <make_file+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <make_file+0xc8>
lea    0xe70(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    11f8 <make_file+0xb8>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c9 <make_file+0x89>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b4 <make_file+0x64>
mov    %rdi,%r14
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c7 <make_file+0x77>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xecb(%rip),%r14
lea    0xe95(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
call   1060 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1190 <make_file+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11dd <make_file+0x8d>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11dd <make_file+0x8d>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"pfile is NULL\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"open file [%s] faild\0A\00"
@.str.3 = [47 x i8] c"abcdefg hijklmn opqrst uvwxyz. hello, world !\0A\00"
@.str.4 = [10 x i8] c"[%02d] %s\00"
define i32 @make_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* null, %14
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %17)
store i32 1, i32* %2
br label %34
19: ; preds = %11
store i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8** %5
store i32 0, i32* %6
store i32 0, i32* %6
br label %20
20: ; preds = %28, %19
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 100
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32*, i32** %4
%25 = load i32, i32* %6
%26 = load i8*, i8** %5
%27 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %25, i8* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %20
31: ; preds = %20
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %2
br label %34
34: ; preds = %31, %16, %9
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"open file [%s] faild\0A\00"
@.str.3 = [47 x i8] c"abcdefg hijklmn opqrst uvwxyz. hello, world !\0A\00"
@.str.4 = [10 x i8] c"[%02d] %s\00"
@str = [14 x i8] c"pfile is NULL\00"
define i32 @make_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %17
5: ; preds = %1
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %17
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ 0, %5 ]
%12 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = tail call i32 @fclose(i32* %6)
br label %17
17: ; preds = %8, %15, %3
%18 = phi i32 [ -1, %3 ], [ 1, %8 ], [ 0, %15 ]
ret i32 %18
}