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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void logError(char *string) {
  srand(time(NULL));
  char errorName[13];
  strcat(errorName, "error");
  for (int i = 0; i < 10; i++)
    sprintf(errorName + strlen(errorName), "%i", rand() % 10);
  strcat(errorName, ".txt");
  printf("Error logged in ");
  printf("%s\n", errorName);
  time_t timet = time(NULL);
  char *time_string = ctime(&timet);
  FILE *file = fopen(errorName, "w+");
  fprintf(file, "On %s", time_string);
  fprintf(file, "The following error was produced:\n");
  fprintf(file, "\t%s", string);
  fclose(file);
}


x86 assembly (clang, -O0):
<logError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    -0x15(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10b0 <strcat@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    123b <logError+0x8b>
lea    -0x15(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x15(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10d0 <rand@plt>
mov    -0x38(%rbp),%rdi
mov    $0xa,%ecx
cltd
idiv   %ecx
lea    0xdde(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e3 <logError+0x33>
lea    -0x15(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   10b0 <strcat@plt>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x15(%rbp),%rsi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x28(%rbp)
lea    -0x15(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd80(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logError>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe0d(%rip),%rsi
lea    0x7(%rsp),%r12
mov    %r12,%rdi
call   10c0 <strcat@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
lea    0xdc8(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x7,%rbx
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <sprintf@plt>
lea    0xb67(%rip),%rsi
mov    %r12,%rdi
call   10c0 <strcat@plt>
lea    0xb5d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rax,%r15
lea    0xb40(%rip),%rsi
mov    %r12,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xb31(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xb23(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
lea    0xb2d(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"error\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [17 x i8] c"Error logged in \00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [6 x i8] c"On %s\00"
@.str.7 = [35 x i8] c"The following error was produced:\0A\00"
@.str.8 = [4 x i8] c"\09%s\00"
define void @logError(i8* %0) {
%2 = alloca i8*
%3 = alloca [13 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %2
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = getelementptr inbounds [13 x i8], [13 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))
store i32 0, i32* %4
br label %12
12: ; preds = %24, %1
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 10
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %15
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %12
27: ; preds = %12
%28 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = call i32 @time(i32* null)
store i32 %33, i32* %5
%34 = call i8* @ctime(i32* %5)
store i8* %34, i8** %6
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = load i8*, i8** %6
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %7
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32*, i32** %7
%43 = load i8*, i8** %2
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"error\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [17 x i8] c"Error logged in \00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [6 x i8] c"On %s\00"
@.str.7 = [35 x i8] c"The following error was produced:\0A\00"
@.str.8 = [4 x i8] c"\09%s\00"
define void @logError(i8* %0) {
%2 = alloca [13 x i8]
%3 = alloca i32
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strlen(i8* %6)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %9
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 10
%13 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @strlen(i8* %6)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %15
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 10
%19 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @strlen(i8* %6)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %21
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 10
%25 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 @strlen(i8* %6)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %27
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 10
%31 = call i32 @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @strlen(i8* %6)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %33
%35 = call i32 (...) @rand()
%36 = srem i32 %35, 10
%37 = call i32 @sprintf(i8* %34, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 @strlen(i8* %6)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %39
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 10
%43 = call i32 @sprintf(i8* %40, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 @strlen(i8* %6)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %45
%47 = call i32 (...) @rand()
%48 = srem i32 %47, 10
%49 = call i32 @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = call i32 @strlen(i8* %6)
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %51
%53 = call i32 (...) @rand()
%54 = srem i32 %53, 10
%55 = call i32 @sprintf(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = call i32 @strlen(i8* %6)
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %57
%59 = call i32 (...) @rand()
%60 = srem i32 %59, 10
%61 = call i32 @sprintf(i8* %58, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = call i32 @strlen(i8* %6)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %63
%65 = call i32 (...) @rand()
%66 = srem i32 %65, 10
%67 = call i32 @sprintf(i8* %64, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%68 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%70 = call i32 @puts(i8* %6)
%71 = bitcast i32* %3 to i8*
%72 = call i32 @time(i32* null)
store i32 %72, i32* %3
%73 = call i8* @ctime(i32* %3)
%74 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %73)
%76 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i64 34, i64 1, i32* %74)
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%78 = call i32 @fclose(i32* %74)
ret void
}