#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 */
int /*<<< orphan*/ printf(char *, int);
double add(double **a, int sizei, int sizej) {
  double sum = 0;
  for (int ij = 0; ij < sizei * sizej; ij++) {
    printf("%d", ij);
    sum += *(*a + ij);
    if (*(*a + ij) == 0)
      return sum;
  }
  return sum;
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    11b1 <add+0xa1>
mov    -0x24(%rbp),%esi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119e <add+0x8e>
jp     119e <add+0x8e>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bb <add+0xab>
jmp    11a3 <add+0x93>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <add+0x21>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
imul   %edx,%esi
test   %esi,%esi
jle    1177 <add+0x67>
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xeda(%rip),%r15
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    (%r14),%rax
movsd  (%rax,%rbx,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
ucomisd 0xe98(%rip),%xmm0
jne    116c <add+0x5c>
jnp    1180 <add+0x70>
add    $0x1,%rbx
cmp    %r12,%rbx
jb     1140 <add+0x30>
jmp    1180 <add+0x70>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define double @add(double** %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %10
10: ; preds = %37, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = mul nsw i32 %12, %13
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %40
16: ; preds = %10
%17 = load i32, i32* %9
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load double**, double*** %5
%20 = load double*, double** %19
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double, double* %8
%26 = fadd double %25, %24
store double %26, double* %8
%27 = load double**, double*** %5
%28 = load double*, double** %27
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fcmp oeq double %32, 0.000000e+00
br i1 %33, label %34, label %36
34: ; preds = %16
%35 = load double, double* %8
store double %35, double* %4
br label %42
36: ; preds = %16
br label %37
37: ; preds = %36
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %10
40: ; preds = %10
%41 = load double, double* %8
store double %41, double* %4
br label %42
42: ; preds = %40, %34
%43 = load double, double* %4
ret double %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define double @add(double** nocapture %0, i32 %1, i32 %2) {
%4 = mul nsw i32 %2, %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %8, %6
%9 = phi i64 [ %18, %8 ], [ 0, %6 ]
%10 = phi double [ %16, %8 ], [ 0.000000e+00, %6 ]
%11 = trunc i64 %9 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load double*, double** %0
%14 = getelementptr inbounds double, double* %13, i64 %9
%15 = load double, double* %14
%16 = fadd double %10, %15
%17 = fcmp une double %15, 0.000000e+00
%18 = add nuw nsw i64 %9, 1
%19 = icmp ult i64 %18, %7
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %8, label %21
21: ; preds = %8, %3
%22 = phi double [ 0.000000e+00, %3 ], [ %16, %8 ]
ret double %22
}