#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__ calloc(int, int);
int *mymalloc(int *);
int main() {
  int *_a = (int *)calloc(10, sizeof(int));
  int *a = mymalloc(_a);
  int b[10];
  int i;
  for (i = 0; i < 10; i++)
    b[i] = a[i];
  int x = a[i - 1] + b[i - 1];
  if (x == 0)
    return 42;
  else
    return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0xa,-0x44(%rbp)
jge    1181 <main+0x61>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1156 <main+0x36>
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jne    11b7 <main+0x97>
movl   $0x2a,-0x4(%rbp)
jmp    11be <main+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    $0xa,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%rdi
call   1040 <mymalloc@plt>
mov    0x20(%rax),%rcx
mov    %rcx,0x20(%rsp)
movups (%rax),%xmm0
movups 0x10(%rax),%xmm1
movaps %xmm1,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x24(%rax),%eax
xor    %ecx,%ecx
add    0x24(%rsp),%eax
mov    $0x2a,%eax
cmovne %ecx,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [10 x i32]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @calloc(i32 10, i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = call i32* @mymalloc(i32* %9)
store i32* %10, i32** %3
store i32 0, i32* %5
br label %11
11: ; preds = %23, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %14
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %11
26: ; preds = %11
%27 = load i32*, i32** %3
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = add nsw i32 %32, %37
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %26
store i32 42, i32* %1
br label %43
42: ; preds = %26
store i32 0, i32* %1
br label %43
43: ; preds = %42, %41
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i64 @calloc(i32 10, i32 4)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i32* @mymalloc(i32* %4)
%6 = bitcast i32* %5 to i8*
%7 = getelementptr inbounds i32, i32* %5, i64 9
%8 = load i32, i32* %7
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%10 = load i32, i32* %9
%11 = sub i32 0, %10
%12 = icmp eq i32 %8, %11
%13 = select i1 %12, i32 42, i32 0
ret i32 %13
}