#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, int, int, int, int, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int write_pstats_communication(int input_key, int part_key, int my_rank,
                               int nprocs, int nghb_cnt, int nghb_idx,
                               int *send_cnt, int **send_lst, int *recv_cnt,
                               int **recv_lst) {
  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, "COMMUNICATION %d %d %d %d %d %d %d %d %d %d %d %d\n", input_key,
          part_key, my_rank, nprocs, nghb_cnt, nghb_idx, send_lst[nghb_idx][0],
          send_lst[nghb_idx][(send_cnt[nghb_idx] - 1) / 2],
          send_lst[nghb_idx][send_cnt[nghb_idx] - 1], recv_lst[nghb_idx][0],
          recv_lst[nghb_idx][(recv_cnt[nghb_idx] - 1) / 2],
          recv_lst[nghb_idx][recv_cnt[nghb_idx] - 1]);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_pstats_communication>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %edx,-0x38(%rbp)
mov    %ecx,-0x3c(%rbp)
mov    %r8d,-0x40(%rbp)
mov    %r9d,-0x44(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xe6a(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11d6 <write_pstats_communication+0x86>
lea    -0x60(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1309 <write_pstats_communication+0x1b9>
mov    -0x68(%rbp),%rdi
mov    -0x30(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x40(%rbp),%r13d
mov    -0x44(%rbp),%r12d
mov    0x18(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    (%rax),%r15d
mov    0x18(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %rax,-0x88(%rbp)
mov    0x10(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,4),%eax
sub    $0x1,%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x88(%rbp),%rax
movslq %edx,%rdx
mov    (%rax,%rdx,4),%r14d
mov    0x18(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    0x10(%rbp),%rdx
movslq -0x44(%rbp),%rsi
mov    (%rdx,%rsi,4),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rax,%rdx,4),%ebx
mov    0x28(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    (%rax),%r11d
mov    0x28(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %rax,-0x78(%rbp)
mov    0x20(%rbp),%rax
movslq -0x44(%rbp),%rdx
mov    (%rax,%rdx,4),%eax
sub    $0x1,%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    -0x7c(%rbp),%edx
mov    %eax,%esi
mov    -0x78(%rbp),%rax
movslq %esi,%rsi
mov    (%rax,%rsi,4),%r10d
mov    0x28(%rbp),%rax
movslq -0x44(%rbp),%rsi
mov    (%rax,%rsi,8),%rax
mov    %rax,-0x70(%rbp)
mov    0x20(%rbp),%rsi
movslq -0x44(%rbp),%rax
mov    (%rsi,%rax,4),%esi
mov    -0x70(%rbp),%rax
sub    $0x1,%esi
movslq %esi,%rsi
mov    (%rax,%rsi,4),%eax
lea    0xd64(%rip),%rsi
mov    %r13d,(%rsp)
mov    %r12d,0x8(%rsp)
mov    %r15d,0x10(%rsp)
mov    %r14d,0x18(%rsp)
mov    %ebx,0x20(%rsp)
mov    %r11d,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %eax,0x38(%rsp)
call   1050 <fprintf@plt>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pstats_communication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %esi,%ebp
mov    %edi,0xc(%rsp)
lea    0xe89(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     124d <write_pstats_communication+0xfd>
mov    %rax,%rbx
mov    0x88(%rsp),%r9
mov    0x80(%rsp),%r8
mov    0x78(%rsp),%rsi
mov    0x70(%rsp),%rdi
movslq %r14d,%rax
mov    (%rsi,%rax,8),%rsi
mov    (%rsi),%ecx
mov    %rcx,0x18(%rsp)
movslq (%rdi,%rax,4),%rdi
lea    -0x1(%rdi),%rdx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
sar    %ecx
movslq %ecx,%rcx
mov    (%rsi,%rcx,4),%ecx
mov    %rcx,0x10(%rsp)
mov    -0x4(%rsi,%rdi,4),%r14d
mov    (%r9,%rax,8),%rcx
mov    (%rcx),%r10d
movslq (%r8,%rax,4),%rdx
lea    -0x1(%rdx),%rsi
mov    %esi,%edi
shr    $0x1f,%edi
add    %esi,%edi
sar    %edi
movslq %edi,%rsi
mov    %r15,%r11
mov    (%rcx,%rsi,4),%r15d
mov    %r12d,%r9d
mov    -0x4(%rcx,%rdx,4),%r12d
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
mov    0xc(%rsp),%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
push   %r12
push   %r15
push   %r10
push   %r14
push   0x30(%rsp)
push   0x40(%rsp)
push   %rax
push   %r11
call   1050 <fprintf@plt>
add    $0x40,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1263 <write_pstats_communication+0x113>
lea    0xdbc(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x38,%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 = [51 x i8] c"COMMUNICATION %d %d %d %d %d %d %d %d %d %d %d %d\0A\00"
define i32 @write_pstats_communication(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* %6, i32** %7, i32* %8, i32** %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i32**
%20 = alloca i32*
%21 = alloca i32**
%22 = alloca [20 x i8]
%23 = alloca i32*
store i32 %0, i32* %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store i32* %6, i32** %18
store i32** %7, i32*** %19
store i32* %8, i32** %20
store i32** %9, i32*** %21
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %22, i64 0, i64 0
%25 = load i32, i32* %14
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %22, i64 0, i64 0
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %23
%29 = load i32*, i32** %23
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %10
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %22, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %11
br label %117
34: ; preds = %10
%35 = load i32*, i32** %23
%36 = load i32, i32* %12
%37 = load i32, i32* %13
%38 = load i32, i32* %14
%39 = load i32, i32* %15
%40 = load i32, i32* %16
%41 = load i32, i32* %17
%42 = load i32**, i32*** %19
%43 = load i32, i32* %17
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32*, i32** %42, i64 %44
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 0
%48 = load i32, i32* %47
%49 = load i32**, i32*** %19
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32*, i32** %49, i64 %51
%53 = load i32*, i32** %52
%54 = load i32*, i32** %18
%55 = load i32, i32* %17
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32, i32* %57
%59 = sub nsw i32 %58, 1
%60 = sdiv i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %53, i64 %61
%63 = load i32, i32* %62
%64 = load i32**, i32*** %19
%65 = load i32, i32* %17
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32*, i32** %64, i64 %66
%68 = load i32*, i32** %67
%69 = load i32*, i32** %18
%70 = load i32, i32* %17
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
%74 = sub nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %68, i64 %75
%77 = load i32, i32* %76
%78 = load i32**, i32*** %21
%79 = load i32, i32* %17
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32*, i32** %78, i64 %80
%82 = load i32*, i32** %81
%83 = getelementptr inbounds i32, i32* %82, i64 0
%84 = load i32, i32* %83
%85 = load i32**, i32*** %21
%86 = load i32, i32* %17
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32*, i32** %85, i64 %87
%89 = load i32*, i32** %88
%90 = load i32*, i32** %20
%91 = load i32, i32* %17
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %90, i64 %92
%94 = load i32, i32* %93
%95 = sub nsw i32 %94, 1
%96 = sdiv i32 %95, 2
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %89, i64 %97
%99 = load i32, i32* %98
%100 = load i32**, i32*** %21
%101 = load i32, i32* %17
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32*, i32** %100, i64 %102
%104 = load i32*, i32** %103
%105 = load i32*, i32** %20
%106 = load i32, i32* %17
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = load i32, i32* %108
%110 = sub nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %104, i64 %111
%113 = load i32, i32* %112
%114 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37, i32 %38, i32 %39, i32 %40, i32 %41, i32 %48, i32 %63, i32 %77, i32 %84, i32 %99, i32 %113)
%115 = load i32*, i32** %23
%116 = call i32 @fclose(i32* %115)
store i32 0, i32* %11
br label %117
117: ; preds = %34, %31
%118 = load i32, i32* %11
ret i32 %118
}

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 = [51 x i8] c"COMMUNICATION %d %d %d %d %d %d %d %d %d %d %d %d\0A\00"
define i32 @write_pstats_communication(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* nocapture %6, i32** nocapture %7, i32* nocapture %8, i32** nocapture %9) {
%11 = alloca [20 x i8]
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%13 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %2)
%14 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %48
18: ; preds = %10
%19 = sext i32 %5 to i64
%20 = getelementptr inbounds i32*, i32** %7, i64 %19
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %6, i64 %19
%24 = load i32, i32* %23
%25 = add nsw i32 %24, -1
%26 = sdiv i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %21, i64 %27
%29 = load i32, i32* %28
%30 = sext i32 %25 to i64
%31 = getelementptr inbounds i32, i32* %21, i64 %30
%32 = load i32, i32* %31
%33 = getelementptr inbounds i32*, i32** %9, i64 %19
%34 = load i32*, i32** %33
%35 = load i32, i32* %34
%36 = getelementptr inbounds i32, i32* %8, i64 %19
%37 = load i32, i32* %36
%38 = add nsw i32 %37, -1
%39 = sdiv i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %34, i64 %40
%42 = load i32, i32* %41
%43 = sext i32 %38 to i64
%44 = getelementptr inbounds i32, i32* %34, i64 %43
%45 = load i32, i32* %44
%46 = tail call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %22, i32 %29, i32 %32, i32 %35, i32 %42, i32 %45)
%47 = tail call i32 @fclose(i32* %14)
br label %48
48: ; preds = %18, %16
%49 = phi i32 [ -1, %16 ], [ 0, %18 ]
ret i32 %49
}