#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void write_testfile(char *filename) {
  char buf[256];
  memset(buf, '\0', sizeof(buf));
  strcat(buf, "test_");
  strcat(buf, filename);
  FILE *check = fopen(buf, "r");
  if (check != NULL) {
    fclose(check);
    printf("Not writing test for %s Testfile exists.\n", filename);
    return;
  }
  FILE *test = fopen(buf, "w+");
  fputs("/**", test);
  for (int i = 0; i <= 56; i++) {
    fputs("*", test);
  }
  fputs("\n", test);
  fputs(" * ", test);
  fputs("Automated Testing For File: ", test);
  fputs(filename, test);
  fputs("\n * \n *", test);
  for (int i = 0; i <= 56; i++) {
    fputs("*", test);
  }
  fputs("/\n\n", test);
  fputs("#include <stdio.h>\n", test);
  fputs("#include <stdlib.h>\n", test);
  fputs("#include \"cunit.h\"\n\n", test);
  fputs("int main(int argc, char** argv)\n", test);
  fputs("{\n", test);
  fputs("    \n", test);
  fputs("}\n", test);
  fclose(test);
}


x86 assembly (clang, -O0):
<write_testfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11ee <write_testfile+0x8e>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
jmp    1397 <write_testfile+0x237>
lea    -0x110(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rsi
lea    0xe1f(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x124(%rbp)
cmpl   $0x38,-0x124(%rbp)
jg     1259 <write_testfile+0xf9>
mov    -0x120(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1225 <write_testfile+0xc5>
mov    -0x120(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
mov    -0x120(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xdaa(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x128(%rbp)
cmpl   $0x38,-0x128(%rbp)
jg     12f3 <write_testfile+0x193>
mov    -0x120(%rbp),%rsi
lea    0xd86(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    12bf <write_testfile+0x15f>
mov    -0x120(%rbp),%rsi
lea    0xd61(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd52(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd53(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd55(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd57(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd65(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd55(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x120(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_testfile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
lea    0xe45(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ea <write_testfile+0x6a>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xe2b(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    1382 <write_testfile+0x202>
lea    0xe41(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe32(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    $0x39,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x2a,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
add    $0xffffffff,%ebp
jne    1220 <write_testfile+0xa0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xdf3(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xdde(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
lea    0xdd7(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    $0x39,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x2a,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
add    $0xffffffff,%ebp
jne    12a0 <write_testfile+0x120>
lea    0xda9(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd94(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd8f(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd8b(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd87(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd8f(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd79(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
lea    0xd66(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test_\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [42 x i8] c"Not writing test for %s Testfile exists.\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [4 x i8] c"/**\00"
@.str.5 = [2 x i8] c"*\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [4 x i8] c" * \00"
@.str.8 = [29 x i8] c"Automated Testing For File: \00"
@.str.9 = [8 x i8] c"\0A * \0A *\00"
@.str.10 = [4 x i8] c"/\0A\0A\00"
@.str.11 = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.12 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.13 = [21 x i8] c"#include \22cunit.h\22\0A\0A\00"
@.str.14 = [33 x i8] c"int main(int argc, char** argv)\0A\00"
@.str.15 = [3 x i8] c"{\0A\00"
@.str.16 = [6 x i8] c" \0A\00"
@.str.17 = [3 x i8] c"}\0A\00"
define void @write_testfile(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 256)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %1
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %2
%23 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %78
24: ; preds = %1
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %5
%27 = load i32*, i32** %5
%28 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %27)
store i32 0, i32* %6
br label %29
29: ; preds = %35, %24
%30 = load i32, i32* %6
%31 = icmp sle i32 %30, 56
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32*, i32** %5
%34 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %33)
br label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %29
38: ; preds = %29
%39 = load i32*, i32** %5
%40 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %39)
%41 = load i32*, i32** %5
%42 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* %41)
%43 = load i32*, i32** %5
%44 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32* %43)
%45 = load i8*, i8** %2
%46 = load i32*, i32** %5
%47 = call i32 @fputs(i8* %45, i32* %46)
%48 = load i32*, i32** %5
%49 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32* %48)
store i32 0, i32* %7
br label %50
50: ; preds = %56, %38
%51 = load i32, i32* %7
%52 = icmp sle i32 %51, 56
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32*, i32** %5
%55 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %54)
br label %56
56: ; preds = %53
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %50
59: ; preds = %50
%60 = load i32*, i32** %5
%61 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* %60)
%62 = load i32*, i32** %5
%63 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i32* %62)
%64 = load i32*, i32** %5
%65 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0), i32* %64)
%66 = load i32*, i32** %5
%67 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i32* %66)
%68 = load i32*, i32** %5
%69 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i32* %68)
%70 = load i32*, i32** %5
%71 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32* %70)
%72 = load i32*, i32** %5
%73 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i32* %72)
%74 = load i32*, i32** %5
%75 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i32* %74)
%76 = load i32*, i32** %5
%77 = call i32 @fclose(i32* %76)
br label %78
78: ; preds = %59, %19
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"test_\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [42 x i8] c"Not writing test for %s Testfile exists.\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [4 x i8] c"/**\00"
@.str.7 = [4 x i8] c" * \00"
@.str.8 = [29 x i8] c"Automated Testing For File: \00"
@.str.9 = [8 x i8] c"\0A * \0A *\00"
@.str.10 = [4 x i8] c"/\0A\0A\00"
@.str.11 = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.12 = [21 x i8] c"#include <stdlib.h>\0A\00"
@.str.13 = [21 x i8] c"#include \22cunit.h\22\0A\0A\00"
@.str.14 = [33 x i8] c"int main(int argc, char** argv)\0A\00"
@.str.15 = [3 x i8] c"{\0A\00"
@.str.16 = [6 x i8] c" \0A\00"
@.str.17 = [3 x i8] c"}\0A\00"
define void @write_testfile(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 256)
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcat(i8* %3, i8* %0)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @fclose(i32* %7)
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %41
12: ; preds = %1
%13 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %13)
br label %21
15: ; preds = %21
%16 = call i32 @fputc(i32 10, i32* %13)
%17 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 3, i64 1, i32* %13)
%18 = call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i64 28, i64 1, i32* %13)
%19 = call i32 @fputs(i8* %0, i32* %13)
%20 = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i64 7, i64 1, i32* %13)
br label %36
21: ; preds = %12, %21
%22 = phi i32 [ 0, %12 ], [ %24, %21 ]
%23 = call i32 @fputc(i32 42, i32* %13)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, 57
br i1 %25, label %15, label %21
26: ; preds = %36
%27 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i64 3, i64 1, i32* %13)
%28 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i64 19, i64 1, i32* %13)
%29 = call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0), i64 20, i64 1, i32* %13)
%30 = call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i64 20, i64 1, i32* %13)
%31 = call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i64 32, i64 1, i32* %13)
%32 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i64 2, i64 1, i32* %13)
%33 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i64 5, i64 1, i32* %13)
%34 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i64 2, i64 1, i32* %13)
%35 = call i32 @fclose(i32* %13)
br label %41
36: ; preds = %15, %36
%37 = phi i32 [ 0, %15 ], [ %39, %36 ]
%38 = call i32 @fputc(i32 42, i32* %13)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, 57
br i1 %40, label %26, label %36
41: ; preds = %26, %9
ret void
}