#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, int,
                           long long);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int write_pstats_exectime(int input_key, int part_key, int read_key,
                          int my_rank, long long time_usec) {
  char pstatsname[20];
  sprintf(pstatsname, "pstats_%d.dat", my_rank);
  FILE *fp = fopen(pstatsname, "a");
  if (fp == NULL) {
    printf("Error opening file %s for writing\n", pstatsname);
    return -1;
  }
  fprintf(fp, "EXECTIME %d %d %d %d %lld\n", input_key, part_key, read_key,
          my_rank, time_usec);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_pstats_exectime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11b6 <write_pstats_exectime+0x66>
lea    -0x40(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <write_pstats_exectime+0x9c>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x20(%rbp),%rax
lea    0xe60(%rip),%rsi
mov    %rax,(%rsp)
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pstats_exectime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r12
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r13d
lea    0xe8d(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %ecx,%edx
call   1070 <sprintf@plt>
lea    0xe85(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c4 <write_pstats_exectime+0x74>
mov    %rax,%rbp
mov    %r12,(%rsp)
lea    0xe8f(%rip),%rsi
mov    %rax,%rdi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
mov    %ebx,%r9d
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11da <write_pstats_exectime+0x8a>
lea    0xe45(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"pstats_%d.dat\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.3 = [27 x i8] c"EXECTIME %d %d %d %d %lld\0A\00"
define i32 @write_pstats_exectime(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca [20 x i8]
%13 = alloca i32*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i64 %4, i64* %11
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%15 = load i32, i32* %10
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %13
%19 = load i32*, i32** %13
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %5
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %6
br label %34
24: ; preds = %5
%25 = load i32*, i32** %13
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i64, i64* %11
%31 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27, i32 %28, i32 %29, i64 %30)
%32 = load i32*, i32** %13
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %6
br label %34
34: ; preds = %24, %21
%35 = load i32, i32* %6
ret i32 %35
}

LLVM IR (-O2):
@.str = [14 x i8] c"pstats_%d.dat\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.3 = [27 x i8] c"EXECTIME %d %d %d %d %lld\0A\00"
define i32 @write_pstats_exectime(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4) {
%6 = alloca [20 x i8]
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%9 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %16
13: ; preds = %5
%14 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3, i64 %4)
%15 = tail call i32 @fclose(i32* %9)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %17
}