#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int msize(char *);
int /*<<< orphan*/ printf(char *);
int test_calloc(void) {
  char *block;
  printf("\tcalloc");
  block = calloc(17, 5);
  if (block[0] || block[84])
    return 1;
  else
    printf(".");
  if (msize(block) < 85)
    return 1;
  else
    printf(".");
  free(block);
  printf(".");
  printf(" passed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x11,%edi
mov    $0x5,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1188 <test_calloc+0x48>
mov    -0x10(%rbp),%rax
movsbl 0x54(%rax),%eax
cmp    $0x0,%eax
je     1194 <test_calloc+0x54>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <test_calloc+0xb2>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <msize@plt>
cmp    $0x55,%eax
jge    11be <test_calloc+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <test_calloc+0xb2>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_calloc>:
push   %rbx
lea    0xe98(%rip),%rdi
call   1060 <printf@plt>
mov    $0x11,%edi
mov    $0x5,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    $0x2e,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1080 <msize@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x55,%ecx
jl     11c7 <test_calloc+0x67>
mov    $0x2e,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x2e,%edi
call   1040 <putchar@plt>
lea    0xe48(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\09calloc\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [10 x i8] c" passed.\0A\00"
define i32 @test_calloc() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @calloc(i32 17, i32 5)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 84
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10, %0
store i32 1, i32* %1
br label %31
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17
%20 = load i8*, i8** %2
%21 = call i32 @msize(i8* %20)
%22 = icmp slt i32 %21, 85
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %1
br label %31
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %31
31: ; preds = %26, %23, %16
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [8 x i8] c"\09calloc\00"
@str = [9 x i8] c" passed.\00"
define i32 @test_calloc() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(85) i8* @calloc(i32 17, i32 5)
%3 = tail call i32 @putchar(i32 46)
%4 = tail call i32 @msize(i8* %2)
%5 = icmp slt i32 %4, 85
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = tail call i32 @putchar(i32 46)
%8 = tail call i32 @free(i8* %2)
%9 = tail call i32 @putchar(i32 46)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %0, %6
%12 = phi i32 [ 0, %6 ], [ 1, %0 ]
ret i32 %12
}