#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*/ abort();
int *calloc(int, int);
scalar_t__ max(int, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int *mem = calloc(sizeof(int), 1000);
  int *mem2 = calloc(sizeof(int), 100);
  int sum = 0;
  for (int i = 0; i < 1000; i++) {
    mem[i] = i;
    for (int j = 0; j < 100; j++) {
      mem2[j] = j;
      sum += max(mem[i], mem2[j]);
    }
  }
  printf("%d\n", sum);
  if (50116650 != sum) {
    abort();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
mov    $0x3e8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
mov    $0x64,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3e8,-0x20(%rbp)
jge    1206 <main+0xc6>
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    11f3 <main+0xb3>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <max@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a5 <main+0x65>
jmp    11f8 <main+0xb8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1183 <main+0x43>
mov    -0x1c(%rbp),%esi
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2fcb82a,%eax
cmp    -0x1c(%rbp),%eax
je     122a <main+0xea>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x4,%edi
mov    $0x3e8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    $0x4,%edi
mov    $0x64,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
xor    %r12d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,(%r14,%r12,4)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,(%r15,%rbx,4)
mov    %r12d,%edi
mov    %ebx,%esi
call   1050 <max@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1190 <main+0x50>
add    $0x1,%r12
cmp    $0x3e8,%r12
jne    1180 <main+0x40>
lea    0xe42(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
cmp    $0x2fcb82a,%ebp
jne    11d8 <main+0x98>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @calloc(i32 4, i32 1000)
store i32* %7, i32** %2
%8 = call i32* @calloc(i32 4, i32 100)
store i32* %8, i32** %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %46, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %49
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i32*, i32** %2
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 %13, i32* %17
store i32 0, i32* %6
br label %18
18: ; preds = %42, %12
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 100
br i1 %20, label %21, label %45
21: ; preds = %18
%22 = load i32, i32* %6
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
%27 = load i32*, i32** %2
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i64 @max(i32 %31, i32 %36)
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = add nsw i64 %39, %37
%41 = trunc i64 %40 to i32
store i32 %41, i32* %4
br label %42
42: ; preds = %21
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %18
45: ; preds = %18
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %9
49: ; preds = %9
%50 = load i32, i32* %4
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %4
%53 = icmp ne i32 50116650, %52
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 (...) @abort()
unreachable
56: ; preds = %49
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32* @calloc(i32 4, i32 1000)
%2 = tail call i32* @calloc(i32 4, i32 100)
br label %6
3: ; preds = %11
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%5 = icmp eq i32 %21, 50116650
br i1 %5, label %26, label %24
6: ; preds = %0, %11
%7 = phi i64 [ 0, %0 ], [ %12, %11 ]
%8 = phi i32 [ 0, %0 ], [ %21, %11 ]
%9 = getelementptr inbounds i32, i32* %1, i64 %7
%10 = trunc i64 %7 to i32
store i32 %10, i32* %9
br label %14
11: ; preds = %14
%12 = add nuw nsw i64 %7, 1
%13 = icmp eq i64 %12, 1000
br i1 %13, label %3, label %6
14: ; preds = %6, %14
%15 = phi i64 [ 0, %6 ], [ %22, %14 ]
%16 = phi i32 [ %8, %6 ], [ %21, %14 ]
%17 = getelementptr inbounds i32, i32* %2, i64 %15
%18 = trunc i64 %15 to i32
store i32 %18, i32* %17
%19 = tail call i64 @max(i32 %10, i32 %18)
%20 = trunc i64 %19 to i32
%21 = add i32 %16, %20
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, 100
br i1 %23, label %11, label %14
24: ; preds = %3
%25 = tail call i32 (...) @abort()
unreachable
26: ; preds = %3
ret i32 0
}