#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(size_t const);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t const);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
int /*<<< orphan*/ unlink(char *);
void print_log(const char *suite_name) {
  const size_t log_name_len = strlen(suite_name) + strlen(".log") + 1;
  char *log_name = malloc(log_name_len);
  FILE *fd = NULL;
  char buf[1024];
  if (NULL == log_name) {
    fprintf(stderr, "ERROR: Out of memory while allocating log file name\n");
    return;
  }
  memset(log_name, 0, log_name_len);
  strcpy(log_name, suite_name);
  strcat(log_name, ".log");
  fd = fopen(log_name, "r");
  if (NULL == fd) {
    free(log_name);
    return;
  }
  while (NULL != fgets(buf, sizeof(buf), fd)) {
    buf[strlen(buf)] = 0;
    fputs(buf, stderr);
  }
  fclose(fd);
  unlink(log_name);
  free(log_name);
}


x86 assembly (clang, -O0):
<print_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x4,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    121f <print_log+0x5f>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    12ea <print_log+0x12a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1279 <print_log+0xb9>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    12ea <print_log+0x12a>
jmp    127e <print_log+0xbe>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   10a0 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12cf <print_log+0x10f>
lea    -0x420(%rbp),%rdi
call   1070 <strlen@plt>
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
jmp    127e <print_log+0xbe>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_log>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r15
call   1070 <strlen@plt>
mov    %rax,%rbx
add    $0x5,%rbx
mov    %rbx,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12b4 <print_log+0xf4>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1090 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
lea    0xe25(%rip),%rsi
mov    %r14,%rdi
call   10e0 <strcat@plt>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12d7 <print_log+0x117>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     128d <print_log+0xcd>
mov    %rsp,%rbx
mov    0x2d8e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <strlen@plt>
movb   $0x0,(%rsp,%rax,1)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1080 <fputs@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1260 <print_log+0xa0>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    10b0 <fprintf@plt>
mov    %r14,%rdi
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"ERROR: Out of memory while allocating log file name\0A\00"
@.str.1 = [5 x i8] c".log\00"
@.str.2 = [2 x i8] c"r\00"
define void @print_log(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [1024 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add i64 %8, 4
%10 = add i64 %9, 1
store i64 %10, i64* %3
%11 = load i64, i64* %3
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %4
store i32* null, i32** %5
%13 = load i8*, i8** %4
%14 = icmp eq i8* null, %13
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %54
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = load i64, i64* %3
%21 = call i32 @memset(i8* %19, i32 0, i64 %20)
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %5
%29 = load i32*, i32** %5
%30 = icmp eq i32* null, %29
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
br label %54
34: ; preds = %18
br label %35
35: ; preds = %40, %34
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = load i32*, i32** %5
%38 = call i32* @fgets(i8* %36, i32 1024, i32* %37)
%39 = icmp ne i32* null, %38
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = load i32, i32* @stderr
%46 = call i32 @fputs(i8* %44, i32 %45)
br label %35
47: ; preds = %35
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %4
%51 = call i32 @unlink(i8* %50)
%52 = load i8*, i8** %4
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %47, %31, %15
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"ERROR: Out of memory while allocating log file name\0A\00"
@.str.1 = [5 x i8] c".log\00"
@.str.2 = [2 x i8] c"r\00"
define void @print_log(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, 5
%5 = tail call i8* @malloc(i64 %4)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = icmp eq i8* %5, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %33
11: ; preds = %1
%12 = tail call i32 @memset(i8* %5, i32 0, i64 %4)
%13 = tail call i32 @strcpy(i8* %5, i8* %0)
%14 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = call i32* @fgets(i8* %6, i32 1024, i32* %15)
%19 = icmp eq i32* %18, null
br i1 %19, label %29, label %22
20: ; preds = %11
%21 = tail call i32 @free(i8* %5)
br label %33
22: ; preds = %17, %22
%23 = call i64 @strlen(i8* %6)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* %6, i32 %25)
%27 = call i32* @fgets(i8* %6, i32 1024, i32* %15)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %22
29: ; preds = %22, %17
%30 = call i32 @fclose(i32* %15)
%31 = call i32 @unlink(i8* %5)
%32 = call i32 @free(i8* %5)
br label %33
33: ; preds = %29, %20, %8
ret void
}