#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char *m_replace_filename(char const *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *devhelp_blank_page(char const *name, char const *filename, int num) {
  char str[256];
  char *path;
  FILE *file;
  sprintf(str, "chapter%i.html", num);
  path = m_replace_filename(filename, str);
  printf("Writing %s.\n", path);
  file = fopen(path, "w");
  if (file) {
    fprintf(file, "<html>\n<head><title>%s</title></head>\n<body>\n", name);
    fprintf(file, "<h1>%s</h1>", name);
    fprintf(file,
            "<p>Use the table of contents to navigate through this chapter.");
    fprintf(file, "</body>\n</html>\n");
    fclose(file);
  }
  return path;
}


x86 assembly (clang, -O0):
<devhelp_blank_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe79(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1080 <m_replace_filename@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x128(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
je     1246 <devhelp_blank_page+0xe6>
mov    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%rdi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x128(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devhelp_blank_page>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe77(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <m_replace_filename@plt>
mov    %rax,%r15
lea    0xe66(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe64(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     122a <devhelp_blank_page+0xba>
mov    %rax,%rbx
lea    0xe4f(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe61(%rip),%rdi
mov    $0x3e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe87(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"chapter%i.html\00"
@.str.1 = [13 x i8] c"Writing %s.\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [46 x i8] c"<html>\0A<head><title>%s</title></head>\0A<body>\0A\00"
@.str.4 = [12 x i8] c"<h1>%s</h1>\00"
@.str.5 = [63 x i8] c"<p>Use the table of contents to navigate through this chapter.\00"
@.str.6 = [17 x i8] c"</body>\0A</html>\0A\00"
define i8* @devhelp_blank_page(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* %6
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %5
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i8* @m_replace_filename(i8* %13, i8* %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %8
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %35
22: ; preds = %3
%23 = load i32*, i32** %9
%24 = load i8*, i8** %4
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %9
%27 = load i8*, i8** %4
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i32*, i32** %9
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32*, i32** %9
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32*, i32** %9
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %22, %3
%36 = load i8*, i8** %8
ret i8* %36
}

LLVM IR (-O2):
@.str = [15 x i8] c"chapter%i.html\00"
@.str.1 = [13 x i8] c"Writing %s.\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [46 x i8] c"<html>\0A<head><title>%s</title></head>\0A<body>\0A\00"
@.str.4 = [12 x i8] c"<h1>%s</h1>\00"
@.str.5 = [63 x i8] c"<p>Use the table of contents to navigate through this chapter.\00"
@.str.6 = [17 x i8] c"</body>\0A</html>\0A\00"
define i8* @devhelp_blank_page(i8* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
%7 = call i8* @m_replace_filename(i8* %1, i8* %5)
%8 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%14 = call i64 @fwrite(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0), i64 62, i64 1, i32* %9)
%15 = call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i64 16, i64 1, i32* %9)
%16 = call i32 @fclose(i32* %9)
br label %17
17: ; preds = %11, %3
ret i8* %7
}