#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 */
struct utsname {
  char const *nodename;
  char const *release;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            ...);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ stdout;
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ uname(struct utsname *);
FILE *prepare_output(const char *dirname) {
  FILE *output = NULL;
  int len;
  char *filename;
  struct utsname sysdata;
  DIR *dir;
  dir = opendir(dirname);
  if (dir == NULL) {
    if (mkdir(dirname, 0755)) {
      perror("mkdir");
      fprintf(stderr, "error: Cannot create dir %s\n", dirname);
      return NULL;
    }
  }
  len = strlen(dirname) + 30;
  filename = malloc(sizeof(char) * len);
  if (uname(&sysdata) == 0) {
    len += strlen(sysdata.nodename) + strlen(sysdata.release);
    filename = realloc(filename, sizeof(char) * len);
    if (filename == NULL) {
      perror("realloc");
      return NULL;
    }
    snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", dirname,
             sysdata.nodename, sysdata.release, time(NULL));
  } else {
    snprintf(filename, len - 1, "%s/benchmark_%li.log", dirname, time(NULL));
  }
  do {
  } while (0);
  output = fopen(filename, "w+");
  if (output == NULL) {
    perror("fopen");
    fprintf(stderr, "error: unable to open logfile\n");
  }
  fprintf(stdout, "Logfile: %s\n", filename);
  free(filename);
  fprintf(output, "#round load sleep performance powersave percentage\n");
  return output;
}


x86 assembly (clang, -O0):
<prepare_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1241 <prepare_output+0x81>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     123c <prepare_output+0x7c>
lea    0xdf2(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13fe <prepare_output+0x23e>
jmp    1241 <prepare_output+0x81>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1e,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
call   1080 <uname@plt>
cmp    $0x0,%rax
jne    132e <prepare_output+0x16e>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d3 <prepare_output+0x113>
lea    0xd62(%rip),%rdi
call   10e0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    13fe <prepare_output+0x23e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x50(%rbp),%r9
lea    0xd0c(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    1372 <prepare_output+0x1b2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    -0x88(%rbp),%rdi
mov    -0x7c(%rbp),%esi
mov    -0x78(%rbp),%rcx
movslq %eax,%r8
lea    0xcdb(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    1377 <prepare_output+0x1b7>
jmp    137c <prepare_output+0x1bc>
mov    -0x28(%rbp),%rdi
lea    0xcd4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    13bf <prepare_output+0x1ff>
lea    0xcbc(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%rdi
lea    0xcac(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c12(%rip),%rax
movslq (%rax),%rdi
mov    -0x28(%rbp),%rdx
lea    0xcaf(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
lea    0xca1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1050 <opendir@plt>
test   %rax,%rax
jne    1201 <prepare_output+0x31>
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jne    1341 <prepare_output+0x171>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0x1e(%rbx),%r13d
mov    %r13d,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rdi
call   1080 <uname@plt>
test   %rax,%rax
je     124e <prepare_output+0x7e>
add    $0x1d,%ebx
xor    %edi,%edi
call   10a0 <time@plt>
movslq %eax,%r8
lea    0xe09(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    12ae <prepare_output+0xde>
mov    0x8(%rsp),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r13d,%ebp
add    %eax,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   10c0 <realloc@plt>
test   %rax,%rax
je     136c <prepare_output+0x19c>
mov    %rax,%r15
add    $0xffffffff,%ebp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,(%rsp)
lea    0xd92(%rip),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0xda6(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1313 <prepare_output+0x143>
mov    0x2d0c(%rip),%rax
movslq (%rax),%rdi
lea    0xdad(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xda1(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd44(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%rcx
lea    0xd34(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
call   10f0 <fwrite@plt>
jmp    12c5 <prepare_output+0xf5>
lea    0xcb8(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%rdi
lea    0xca8(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1301 <prepare_output+0x131>
lea    0xcb0(%rip),%rdi
call   10e0 <perror@plt>
xor    %ebx,%ebx
jmp    1301 <prepare_output+0x131>

LLVM IR (-O0):
%struct.utsname = type { i8*, i8* }
@.str = [6 x i8] c"mkdir\00"
@stderr = global i32* null
@.str.1 = [29 x i8] c"error: Cannot create dir %s\0A\00"
@.str.2 = [8 x i8] c"realloc\00"
@.str.3 = [27 x i8] c"%s/benchmark_%s_%s_%li.log\00"
@.str.4 = [21 x i8] c"%s/benchmark_%li.log\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [6 x i8] c"fopen\00"
@.str.7 = [31 x i8] c"error: unable to open logfile\0A\00"
@stdout = global i32 0
@.str.8 = [13 x i8] c"Logfile: %s\0A\00"
@.str.9 = [52 x i8] c"#round load sleep performance powersave percentage\0A\00"
define i32* @prepare_output(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.utsname
%8 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %4
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i64 @mkdir(i8* %14, i32 493)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** @stderr
%20 = load i8*, i8** %3
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32* null, i32** %2
br label %96
22: ; preds = %13
br label %23
23: ; preds = %22, %1
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 30
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %6
%32 = call i64 @uname(%struct.utsname* %7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %65
34: ; preds = %23
%35 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 1
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %37, %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, %41
store i32 %43, i32* %5
%44 = load i8*, i8** %6
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = mul i64 1, %46
%48 = trunc i64 %47 to i32
%49 = call i8* @realloc(i8* %44, i32 %48)
store i8* %49, i8** %6
%50 = load i8*, i8** %6
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %54
52: ; preds = %34
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32* null, i32** %2
br label %96
54: ; preds = %34
%55 = load i8*, i8** %6
%56 = load i32, i32* %5
%57 = sub nsw i32 %56, 1
%58 = load i8*, i8** %3
%59 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 1
%62 = load i8*, i8** %61
%63 = call i32 @time(i32* null)
%64 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %55, i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %58, i8* %60, i8* %62, i32 %63)
br label %74
65: ; preds = %23
%66 = load i8*, i8** %6
%67 = load i32, i32* %5
%68 = sub nsw i32 %67, 1
%69 = load i8*, i8** %3
%70 = call i32 @time(i32* null)
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i8*
%73 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %66, i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %69, i8* %72)
br label %74
74: ; preds = %65, %54
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
%77 = load i8*, i8** %6
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %78, i32** %4
%79 = load i32*, i32** %4
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %85
81: ; preds = %76
%82 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%83 = load i32*, i32** @stderr
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
br label %85
85: ; preds = %81, %76
%86 = load i32, i32* @stdout
%87 = sext i32 %86 to i64
%88 = inttoptr i64 %87 to i32*
%89 = load i8*, i8** %6
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %88, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %89)
%91 = load i8*, i8** %6
%92 = call i32 @free(i8* %91)
%93 = load i32*, i32** %4
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0))
%95 = load i32*, i32** %4
store i32* %95, i32** %2
br label %96
96: ; preds = %85, %52, %17
%97 = load i32*, i32** %2
ret i32* %97
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8* }
@.str = [6 x i8] c"mkdir\00"
@stderr = global i32* null
@.str.1 = [29 x i8] c"error: Cannot create dir %s\0A\00"
@.str.2 = [8 x i8] c"realloc\00"
@.str.3 = [27 x i8] c"%s/benchmark_%s_%s_%li.log\00"
@.str.4 = [21 x i8] c"%s/benchmark_%li.log\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [6 x i8] c"fopen\00"
@.str.7 = [31 x i8] c"error: unable to open logfile\0A\00"
@stdout = global i32 0
@.str.8 = [13 x i8] c"Logfile: %s\0A\00"
@.str.9 = [52 x i8] c"#round load sleep performance powersave percentage\0A\00"
define noalias i32* @prepare_output(i8* %0) {
%2 = alloca %struct.utsname
%3 = bitcast %struct.utsname* %2 to i8*
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = tail call i64 @mkdir(i8* %0, i32 493)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** @stderr
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %57
13: ; preds = %6, %1
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, 30
%16 = tail call i8* @malloc(i32 %15)
%17 = call i64 @uname(%struct.utsname* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %13
%20 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = tail call i32 @strlen(i8* %21)
%23 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 1
%24 = load i8*, i8** %23
%25 = tail call i32 @strlen(i8* %24)
%26 = add i32 %22, %15
%27 = add i32 %26, %25
%28 = tail call i8* @realloc(i8* %16, i32 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %57
32: ; preds = %19
%33 = add nsw i32 %27, -1
%34 = tail call i32 @time(i32* null)
%35 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %28, i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %21, i8* %24, i32 %34)
br label %42
36: ; preds = %13
%37 = add nsw i32 %14, 29
%38 = tail call i32 @time(i32* null)
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
%41 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %16, i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %40)
br label %42
42: ; preds = %32, %36
%43 = phi i8* [ %28, %32 ], [ %16, %36 ]
%44 = tail call i32* @fopen(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32*, i32** @stderr
%49 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64 30, i64 1, i32* %48)
br label %50
50: ; preds = %46, %42
%51 = load i32, i32* @stdout
%52 = sext i32 %51 to i64
%53 = inttoptr i64 %52 to i32*
%54 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %43)
%55 = tail call i32 @free(i8* %43)
%56 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0), i64 51, i64 1, i32* %44)
br label %57
57: ; preds = %50, %30, %9
%58 = phi i32* [ null, %9 ], [ null, %30 ], [ %44, %50 ]
ret i32* %58
}