#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(size_t, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int *calloc_init_vector(size_t nmemb, size_t size) {
  unsigned int i;
  int *vect;
  vect = calloc(nmemb, size);
  if (!vect) {
    fprintf(stderr, "Malloc Error\n");
    return NULL;
  }
  for (i = 0; i < nmemb; i++)
    vect[i] = i;
  return vect;
}


x86 assembly (clang, -O0):
<calloc_init_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116e <calloc_init_vector+0x4e>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <calloc_init_vector+0x85>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    119d <calloc_init_vector+0x7d>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1175 <calloc_init_vector+0x55>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_init_vector>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     114e <calloc_init_vector+0x2e>
test   %rbx,%rbx
je     1163 <calloc_init_vector+0x43>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    %eax,(%r14,%rax,4)
add    $0x1,%eax
cmp    %rbx,%rax
jb     1140 <calloc_init_vector+0x20>
jmp    1163 <calloc_init_vector+0x43>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Malloc Error\0A\00"
define i32* @calloc_init_vector(i64 %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
store i64 %0, i64* %4
store i64 %1, i64* %5
%8 = load i64, i64* %4
%9 = load i64, i64* %5
%10 = call i32* @calloc(i64 %8, i64 %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %33
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %28, %16
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = load i64, i64* %4
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* %6
%24 = load i32*, i32** %7
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %17
31: ; preds = %17
%32 = load i32*, i32** %7
store i32* %32, i32** %3
br label %33
33: ; preds = %31, %13
%34 = load i32*, i32** %3
ret i32* %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Malloc Error\0A\00"
define noalias i32* @calloc_init_vector(i64 %0, i64 %1) {
%3 = tail call i32* @calloc(i64 %0, i64 %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp eq i64 %0, 0
br i1 %6, label %17, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %5, %10
%11 = phi i64 [ %15, %10 ], [ 0, %5 ]
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds i32, i32* %3, i64 %11
store i32 %12, i32* %13
%14 = add nuw nsw i64 %11, 1
%15 = and i64 %14, 4294967295
%16 = icmp ult i64 %15, %0
br i1 %16, label %10, label %17
17: ; preds = %10, %5, %7
ret i32* %3
}