#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 */

/* Variables and functions */
scalar_t__ Malloc(int, char *);
int /*<<< orphan*/ coocsr_(int *, int *, double *, int *, int *, double *,
                           int *, int *);
int /*<<< orphan*/ free(int *);
void coocsc(int n, int nnz, double *val, int *col, int *row, double **a,
            int **ja, int **ia, int job) {
  *a = (double *)Malloc(nnz * sizeof(double), "coocsc");
  *ja = (int *)Malloc(nnz * sizeof(int), "coocsc");
  *ia = (int *)Malloc((n + 1) * sizeof(int), "coocsc");
  int i, *ir, *jc;
  if (job == 0) {
    ir = (int *)Malloc(nnz * sizeof(int), "coocsc");
    jc = (int *)Malloc(nnz * sizeof(int), "coocsc");
    for (i = 0; i < nnz; i++) {
      ir[i] = row[i] + 1;
      jc[i] = col[i] + 1;
    }
  } else {
    ir = row;
    jc = col;
  }
  coocsr_(&n, &nnz, val, jc, ir, *a, *ja, *ia);
  if (job == 0) {
    free(ir);
    free(jc);
  }
}


x86 assembly (clang, -O0):
<coocsc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
lea    0xe96(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
lea    0xe76(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rax,%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
lea    0xe52(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rax,%rcx
mov    0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,0x20(%rbp)
jne    1253 <coocsc+0x123>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
lea    0xe28(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
lea    0xe0e(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124e <coocsc+0x11e>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1202 <coocsc+0xd2>
jmp    1263 <coocsc+0x133>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x28(%rbp),%rax
mov    (%rax),%r9
mov    0x10(%rbp),%rax
mov    (%rax),%r10
mov    0x18(%rbp),%rax
mov    (%rax),%rax
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <coocsr_@plt>
cmpl   $0x0,0x20(%rbp)
jne    12b6 <coocsc+0x186>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coocsc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,0x10(%rsp)
mov    %esi,%r13d
mov    %edi,%r12d
mov    %edi,0x4(%rsp)
mov    %esi,(%rsp)
lea    0x0(,%r13,8),%edi
lea    0xe98(%rip),%rsi
call   1050 <Malloc@plt>
mov    %rbp,0x8(%rsp)
mov    %rax,0x0(%rbp)
lea    0x0(,%r13,4),%r15d
mov    %r15d,%edi
lea    0xe78(%rip),%rsi
call   1050 <Malloc@plt>
mov    0x50(%rsp),%rcx
mov    %rax,(%rcx)
lea    0x4(,%r12,4),%edi
mov    0x60(%rsp),%ebp
lea    0xe58(%rip),%rsi
call   1050 <Malloc@plt>
mov    0x58(%rsp),%rcx
mov    %rax,(%rcx)
test   %ebp,%ebp
je     11be <coocsc+0x8e>
mov    %rcx,%rax
jmp    1220 <coocsc+0xf0>
lea    0xe3b(%rip),%r12
mov    %r15d,%edi
mov    %r12,%rsi
call   1050 <Malloc@plt>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %r12,%rsi
call   1050 <Malloc@plt>
test   %r13d,%r13d
jle    1211 <coocsc+0xe1>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,0x0(%rbp,%rcx,4)
mov    (%r14,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
add    $0x1,%rcx
movslq (%rsp),%rdx
cmp    %rdx,%rcx
jl     11f0 <coocsc+0xc0>
mov    %rbp,%rbx
mov    %rax,%r14
mov    0x60(%rsp),%ebp
mov    0x58(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    0x10(%rsp),%rdx
mov    %r14,%rcx
mov    %rbx,%r8
push   (%rax)
mov    0x58(%rsp),%rax
push   (%rax)
call   1030 <coocsr_@plt>
add    $0x10,%rsp
test   %ebp,%ebp
jne    1261 <coocsc+0x131>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"coocsc\00"
define void @coocsc(i32 %0, i32 %1, double* %2, i32* %3, i32* %4, double** %5, i32** %6, i32** %7, i32 %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca double**
%16 = alloca i32**
%17 = alloca i32**
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32*
store i32 %0, i32* %10
store i32 %1, i32* %11
store double* %2, double** %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store double** %5, double*** %15
store i32** %6, i32*** %16
store i32** %7, i32*** %17
store i32 %8, i32* %18
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call i64 @Malloc(i32 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = inttoptr i64 %26 to double*
%28 = load double**, double*** %15
store double* %27, double** %28
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i64 @Malloc(i32 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = inttoptr i64 %33 to i32*
%35 = load i32**, i32*** %16
store i32* %34, i32** %35
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 4
%40 = trunc i64 %39 to i32
%41 = call i64 @Malloc(i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = inttoptr i64 %41 to i32*
%43 = load i32**, i32*** %17
store i32* %42, i32** %43
%44 = load i32, i32* %18
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %88
46: ; preds = %9
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 4
%50 = trunc i64 %49 to i32
%51 = call i64 @Malloc(i32 %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%52 = inttoptr i64 %51 to i32*
store i32* %52, i32** %20
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = mul i64 %54, 4
%56 = trunc i64 %55 to i32
%57 = call i64 @Malloc(i32 %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%58 = inttoptr i64 %57 to i32*
store i32* %58, i32** %21
store i32 0, i32* %19
br label %59
59: ; preds = %84, %46
%60 = load i32, i32* %19
%61 = load i32, i32* %11
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %87
63: ; preds = %59
%64 = load i32*, i32** %14
%65 = load i32, i32* %19
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = add nsw i32 %68, 1
%70 = load i32*, i32** %20
%71 = load i32, i32* %19
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 %69, i32* %73
%74 = load i32*, i32** %13
%75 = load i32, i32* %19
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %74, i64 %76
%78 = load i32, i32* %77
%79 = add nsw i32 %78, 1
%80 = load i32*, i32** %21
%81 = load i32, i32* %19
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
store i32 %79, i32* %83
br label %84
84: ; preds = %63
%85 = load i32, i32* %19
%86 = add nsw i32 %85, 1
store i32 %86, i32* %19
br label %59
87: ; preds = %59
br label %91
88: ; preds = %9
%89 = load i32*, i32** %14
store i32* %89, i32** %20
%90 = load i32*, i32** %13
store i32* %90, i32** %21
br label %91
91: ; preds = %88, %87
%92 = load double*, double** %12
%93 = load i32*, i32** %21
%94 = load i32*, i32** %20
%95 = load double**, double*** %15
%96 = load double*, double** %95
%97 = load i32**, i32*** %16
%98 = load i32*, i32** %97
%99 = load i32**, i32*** %17
%100 = load i32*, i32** %99
%101 = call i32 @coocsr_(i32* %10, i32* %11, double* %92, i32* %93, i32* %94, double* %96, i32* %98, i32* %100)
%102 = load i32, i32* %18
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %91
%105 = load i32*, i32** %20
%106 = call i32 @free(i32* %105)
%107 = load i32*, i32** %21
%108 = call i32 @free(i32* %107)
br label %109
109: ; preds = %104, %91
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"coocsc\00"
define void @coocsc(i32 %0, i32 %1, double* %2, i32* %3, i32* %4, double** nocapture %5, i32** nocapture %6, i32** nocapture %7, i32 %8) {
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
%12 = shl i32 %1, 3
%13 = tail call i64 @Malloc(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = inttoptr i64 %13 to double*
store double* %14, double** %5
%15 = shl i32 %1, 2
%16 = tail call i64 @Malloc(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %6
%18 = shl i32 %0, 2
%19 = add i32 %18, 4
%20 = tail call i64 @Malloc(i32 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %7
%22 = icmp eq i32 %8, 0
br i1 %22, label %23, label %43
23: ; preds = %9
%24 = tail call i64 @Malloc(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = inttoptr i64 %24 to i32*
%26 = tail call i64 @Malloc(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = inttoptr i64 %26 to i32*
%28 = icmp sgt i32 %1, 0
br i1 %28, label %29, label %43
29: ; preds = %23, %29
%30 = phi i64 [ %39, %29 ], [ 0, %23 ]
%31 = getelementptr inbounds i32, i32* %4, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
%34 = getelementptr inbounds i32, i32* %25, i64 %30
store i32 %33, i32* %34
%35 = getelementptr inbounds i32, i32* %3, i64 %30
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
%38 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 %37, i32* %38
%39 = add nuw nsw i64 %30, 1
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %29, label %43
43: ; preds = %29, %23, %9
%44 = phi i32* [ %4, %9 ], [ %25, %23 ], [ %25, %29 ]
%45 = phi i32* [ %3, %9 ], [ %27, %23 ], [ %27, %29 ]
%46 = load double*, double** %5
%47 = load i32*, i32** %6
%48 = load i32*, i32** %7
%49 = call i32 @coocsr_(i32* %10, i32* %11, double* %2, i32* %45, i32* %44, double* %46, i32* %47, i32* %48)
br i1 %22, label %50, label %53
50: ; preds = %43
%51 = call i32 @free(i32* %44)
%52 = call i32 @free(i32* %45)
br label %53
53: ; preds = %50, %43
ret void
}