#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,
                           int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int write_pstats_partition(int input_key, int part_key, int my_rank,
                           int local_intc, int local_extc) {
  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, "PARTITION %d %d %d %d %d\n", input_key, part_key, my_rank,
          local_intc, local_extc);
  fclose(fp);
  return 0;
}


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

x86 assembly (clang, -O2):
<write_pstats_partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r13d
lea    0xe8d(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c2 <write_pstats_partition+0x72>
mov    %rax,%rbx
mov    %r12d,(%rsp)
lea    0xe91(%rip),%rsi
mov    %rax,%rdi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11d8 <write_pstats_partition+0x88>
lea    0xe47(%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 = [26 x i8] c"PARTITION %d %d %d %d %d\0A\00"
define i32 @write_pstats_partition(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%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 i32 %4, i32* %11
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%15 = load i32, i32* %9
%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 i32, i32* %11
%31 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27, i32 %28, i32 %29, i32 %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 = [26 x i8] c"PARTITION %d %d %d %d %d\0A\00"
define i32 @write_pstats_partition(i32 %0, i32 %1, i32 %2, i32 %3, i32 %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 %2)
%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 ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3, i32 %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
}