#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 *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int *values = calloc(100, sizeof(int));
  if (values == NULL) {
    fprintf(stderr, "Failed allocating memory\n");
    return 1;
  }
  values[123] = 123;
  printf("val %d\n", values[178000]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <main+0x4e>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <main+0x79>
mov    -0x10(%rbp),%rax
movl   $0x7b,0x1ec(%rax)
mov    -0x10(%rbp),%rax
mov    0xadd40(%rax),%esi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x64,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1165 <main+0x35>
movl   $0x7b,0x1ec(%rax)
mov    0xadd40(%rax),%esi
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Failed allocating memory\0A\00"
@.str.1 = [8 x i8] c"val %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @calloc(i32 100, i32 4)
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %16
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 123
store i32 123, i32* %11
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 178000
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 0, i32* %1
br label %16
16: ; preds = %9, %6
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Failed allocating memory\0A\00"
@.str.1 = [8 x i8] c"val %d\0A\00"
define i32 @main() {
%1 = tail call i32* @calloc(i32 100, i32 4)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
6: ; preds = %0
%7 = getelementptr inbounds i32, i32* %1, i64 123
store i32 123, i32* %7
%8 = getelementptr inbounds i32, i32* %1, i64 178000
%9 = load i32, i32* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %6, %3
%12 = phi i32 [ 1, %3 ], [ 0, %6 ]
ret i32 %12
}