#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 *, ...);
void print_bpgraph(int nleft, int nright, int *pointers, int *indices,
                   int *vwgts) {
  FILE *file;
  int i, j, nedges, nvtxs;
  nvtxs = nleft + nright;
  nedges = (pointers[nvtxs] - pointers[0]) / 2;
  file = fopen("BPGRAPH", "w");
  fprintf(file, "%d %d\n", nvtxs, nedges);
  for (i = 0; i < nvtxs; i++) {
    if (vwgts != NULL) {
      fprintf(file, "%d     ", vwgts[i]);
    }
    for (j = pointers[i]; j < pointers[i + 1]; j++) {
      fprintf(file, "%d ", indices[j]);
    }
    fprintf(file, "\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<print_bpgraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    124b <print_bpgraph+0x11b>
cmpq   $0x0,-0x20(%rbp)
je     11d9 <print_bpgraph+0xa9>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    122b <print_bpgraph+0xfb>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e7 <print_bpgraph+0xb7>
mov    -0x28(%rbp),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a5 <print_bpgraph+0x75>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bpgraph>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %edi,%r14d
add    %esi,%r14d
movslq %r14d,%rbx
mov    (%rdx,%rbx,4),%eax
sub    (%rdx),%eax
mov    %r8,%rbp
mov    %rcx,0x10(%rsp)
mov    %eax,%r13d
shr    $0x1f,%r13d
add    %eax,%r13d
sar    %r13d
lea    0xe85(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %ebx,%ebx
jle    1230 <print_bpgraph+0xf0>
mov    %r14d,%eax
mov    %rax,(%rsp)
xor    %r13d,%r13d
mov    %rbp,0x8(%rsp)
mov    0x10(%rsp),%rbx
jmp    11db <print_bpgraph+0x9b>
xchg   %ax,%ax
mov    $0xa,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
mov    %rbp,%r13
cmp    (%rsp),%rbp
mov    0x8(%rsp),%rbp
je     1230 <print_bpgraph+0xf0>
test   %rbp,%rbp
je     11f6 <print_bpgraph+0xb6>
mov    0x0(%rbp,%r13,4),%edx
mov    %r15,%rdi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movslq (%r12,%r13,4),%r14
lea    0x1(%r13),%rbp
cmp    0x4(%r12,%r13,4),%r14d
lea    0xe0f(%rip),%r13
jge    11c0 <print_bpgraph+0x80>
nopl   0x0(%rax)
mov    (%rbx,%r14,4),%edx
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r14
movslq (%r12,%rbp,4),%rax
cmp    %rax,%r14
jl     1210 <print_bpgraph+0xd0>
jmp    11c0 <print_bpgraph+0x80>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"BPGRAPH\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
@.str.3 = [8 x i8] c"%d \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @print_bpgraph(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 i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
store i32 %18, i32* %15
%19 = load i32*, i32** %8
%20 = load i32, i32* %15
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %8
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = sub nsw i32 %23, %26
%28 = sdiv i32 %27, 2
store i32 %28, i32* %14
%29 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %11
%30 = load i32*, i32** %11
%31 = load i32, i32* %15
%32 = load i32, i32* %14
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
store i32 0, i32* %12
br label %34
34: ; preds = %78, %5
%35 = load i32, i32* %12
%36 = load i32, i32* %15
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %81
38: ; preds = %34
%39 = load i32*, i32** %10
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i32*, i32** %11
%43 = load i32*, i32** %10
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %41, %38
%50 = load i32*, i32** %8
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
store i32 %54, i32* %13
br label %55
55: ; preds = %72, %49
%56 = load i32, i32* %13
%57 = load i32*, i32** %8
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %57, i64 %60
%62 = load i32, i32* %61
%63 = icmp slt i32 %56, %62
br i1 %63, label %64, label %75
64: ; preds = %55
%65 = load i32*, i32** %11
%66 = load i32*, i32** %9
%67 = load i32, i32* %13
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = load i32, i32* %69
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %64
%73 = load i32, i32* %13
%74 = add nsw i32 %73, 1
store i32 %74, i32* %13
br label %55
75: ; preds = %55
%76 = load i32*, i32** %11
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %78
78: ; preds = %75
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
store i32 %80, i32* %12
br label %34
81: ; preds = %34
%82 = load i32*, i32** %11
%83 = call i32 @fclose(i32* %82)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"BPGRAPH\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
@.str.3 = [8 x i8] c"%d \00"
@.str.4 = [4 x i8] c"%d \00"
define void @print_bpgraph(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture %3, i32* %4) {
%6 = add nsw i32 %1, %0
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %2, i64 %7
%9 = load i32, i32* %8
%10 = load i32, i32* %2
%11 = sub nsw i32 %9, %10
%12 = sdiv i32 %11, 2
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %12)
%15 = icmp sgt i32 %6, 0
br i1 %15, label %16, label %46
16: ; preds = %5
%17 = icmp eq i32* %4, null
%18 = zext i32 %6 to i64
br label %19
19: ; preds = %16, %43
%20 = phi i64 [ 0, %16 ], [ %28, %43 ]
br i1 %17, label %25, label %21
21: ; preds = %19
%22 = getelementptr inbounds i32, i32* %4, i64 %20
%23 = load i32, i32* %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %19
%26 = getelementptr inbounds i32, i32* %2, i64 %20
%27 = load i32, i32* %26
%28 = add nuw nsw i64 %20, 1
%29 = getelementptr inbounds i32, i32* %2, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %27, %30
br i1 %31, label %32, label %43
32: ; preds = %25
%33 = sext i32 %27 to i64
br label %34
34: ; preds = %32, %34
%35 = phi i64 [ %33, %32 ], [ %39, %34 ]
%36 = getelementptr inbounds i32, i32* %3, i64 %35
%37 = load i32, i32* %36
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = add nsw i64 %35, 1
%40 = load i32, i32* %29
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %34, label %43
43: ; preds = %34, %25
%44 = tail call i32 @fputc(i32 10, i32* %13)
%45 = icmp eq i64 %28, %18
br i1 %45, label %46, label %19
46: ; preds = %43, %5
%47 = tail call i32 @fclose(i32* %13)
ret void
}