#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
void toc_file(char *destfilename, int sub) {
  char destfiletoc[1024], destfiledat[1024];
  FILE *ftoc;
  strcpy(destfiletoc, destfilename);
  strcpy(destfiledat, destfilename);
  strcpy(destfiletoc + strlen(destfilename) - 4, ".toc");
  strcpy(destfiledat + strlen(destfilename) - 4, ".dat");
  if ((ftoc = fopen(destfiletoc, "w")) != NULL) {
    fprintf(ftoc, "CD_ROM\n");
    fprintf(ftoc, "// Track 1\n");
    fprintf(ftoc, "TRACK MODE1_RAW");
    if (sub == 1)
      fprintf(ftoc, " RW_RAW\n");
    else
      fprintf(ftoc, "\n");
    fprintf(ftoc, "NO COPY\n");
    fprintf(ftoc, "DATAFILE \"%s\"\n", destfiledat);
    rename(destfilename, destfiledat);
    printf("Create TOC File : %s\n", destfiletoc);
    fclose(ftoc);
  } else {
    printf("%s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<toc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x828(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe10(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x820(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xde2(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
je     1329 <toc_file+0x199>
mov    -0x818(%rbp),%rdi
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x818(%rbp),%rdi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x818(%rbp),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    12af <toc_file+0x11f>
mov    -0x818(%rbp),%rdi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12c4 <toc_file+0x134>
mov    -0x818(%rbp),%rdi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x818(%rbp),%rdi
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x818(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1090 <rename@plt>
lea    -0x410(%rbp),%rsi
lea    0xd3e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x818(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1354 <toc_file+0x1c4>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd22(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toc_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x3fc,%rdi
lea    0xe06(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xded(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xde6(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1313 <toc_file+0x163>
mov    %rax,%rbx
lea    0xdcd(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
lea    0xdbc(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
lea    0xdaf(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
cmp    $0x1,%ebp
jne    12a3 <toc_file+0xf3>
lea    0xda1(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
jmp    12b0 <toc_file+0x100>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xd82(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
lea    0xd72(%rip),%rsi
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <rename@plt>
lea    0xd5f(%rip),%rdi
lea    0x400(%rsp),%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd3b(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".toc\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [8 x i8] c"CD_ROM\0A\00"
@.str.4 = [12 x i8] c"// Track 1\0A\00"
@.str.5 = [16 x i8] c"TRACK MODE1_RAW\00"
@.str.6 = [9 x i8] c" RW_RAW\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [9 x i8] c"NO COPY\0A\00"
@.str.9 = [15 x i8] c"DATAFILE \22%s\22\0A\00"
@.str.10 = [22 x i8] c"Create TOC File : %s\0A\00"
@.str.11 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @toc_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 -4
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %59
31: ; preds = %2
%32 = load i32*, i32** %7
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32*, i32** %7
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32*, i32** %7
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %31
%41 = load i32*, i32** %7
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %46
43: ; preds = %31
%44 = load i32*, i32** %7
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %43, %40
%47 = load i32*, i32** %7
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%49 = load i32*, i32** %7
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %3
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%54 = call i32 @rename(i8* %52, i8* %53)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
br label %65
59: ; preds = %2
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %46
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".toc\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [8 x i8] c"CD_ROM\0A\00"
@.str.4 = [12 x i8] c"// Track 1\0A\00"
@.str.5 = [16 x i8] c"TRACK MODE1_RAW\00"
@.str.6 = [9 x i8] c" RW_RAW\0A\00"
@.str.8 = [9 x i8] c"NO COPY\0A\00"
@.str.9 = [15 x i8] c"DATAFILE \22%s\22\0A\00"
@.str.10 = [22 x i8] c"Create TOC File : %s\0A\00"
@.str.11 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @toc_file(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = call i32 @strcpy(i8* %6, i8* %0)
%9 = call i32 @strlen(i8* %0)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -4
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -4
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %36, label %21
21: ; preds = %2
%22 = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 7, i64 1, i32* %19)
%23 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 11, i64 1, i32* %19)
%24 = call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i64 15, i64 1, i32* %19)
%25 = icmp eq i32 %1, 1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 8, i64 1, i32* %19)
br label %30
28: ; preds = %21
%29 = call i32 @fputc(i32 10, i32* %19)
br label %30
30: ; preds = %28, %26
%31 = call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i64 8, i64 1, i32* %19)
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %6)
%33 = call i32 @rename(i8* %0, i8* %6)
%34 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %5)
%35 = call i32 @fclose(i32* %19)
ret void
36: ; preds = %2
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
}