#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
void fixed_test(int size) {
  char *ptrs[50000];
  int i;
  for (i = 0; i < 50000; ++i) {
    int j;
    ptrs[i] = (char *)calloc(1, size);
    if (ptrs[i] == NULL)
      break;
    for (j = 0; j < size; ++j) {
      if (ptrs[i][j] != '\0') {
        fprintf(stderr, "byte not cleared (size %d, element %d, byte %d)", size,
                i, j);
        exit(1);
      }
      ptrs[i][j] = '\xff';
    }
  }
  while (i-- > 0)
    free(ptrs[i]);
}


x86 assembly (clang, -O0):
<fixed_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x61a94(%rbp)
cmpl   $0xc350,-0x61a94(%rbp)
jge    1254 <fixed_test+0x114>
mov    -0x4(%rbp),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%rcx
movslq -0x61a94(%rbp),%rax
mov    %rcx,-0x61a90(%rbp,%rax,8)
ff
movslq -0x61a94(%rbp),%rax
cmpq   $0x0,-0x61a90(%rbp,%rax,8)
jne    11a2 <fixed_test+0x62>
jmp    1254 <fixed_test+0x114>
movl   $0x0,-0x61a98(%rbp)
mov    -0x61a98(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123b <fixed_test+0xfb>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,8),%rax
ff
movslq -0x61a98(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     120d <fixed_test+0xcd>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x61a94(%rbp),%ecx
mov    -0x61a98(%rbp),%r8d
lea    0xe02(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,8),%rax
ff
movslq -0x61a98(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x61a98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a98(%rbp)
jmp    11ac <fixed_test+0x6c>
jmp    1240 <fixed_test+0x100>
mov    -0x61a94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a94(%rbp)
jmp    1158 <fixed_test+0x18>
jmp    1259 <fixed_test+0x119>
mov    -0x61a94(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x61a94(%rbp)
cmp    $0x0,%eax
jle    128c <fixed_test+0x14c>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
jmp    1259 <fixed_test+0x119>
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x61a80,%rsp
mov    %edi,%ebp
mov    %edi,%ebx
xor    %r14d,%r14d
jmp    116d <fixed_test+0x2d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
cmp    $0xc350,%r14
je     11ae <fixed_test+0x6e>
mov    $0x1,%edi
mov    %ebp,%esi
call   1040 <calloc@plt>
mov    %rax,(%rsp,%r14,8)
test   %rax,%rax
je     11a7 <fixed_test+0x67>
test   %ebp,%ebp
jle    1160 <fixed_test+0x20>
xor    %r8d,%r8d
nopl   0x0(%rax)
cmpb   $0x0,(%rax,%r8,1)
jne    11e0 <fixed_test+0xa0>
movb   $0xff,(%rax,%r8,1)
add    $0x1,%r8
cmp    %r8,%rbx
jne    1190 <fixed_test+0x50>
jmp    1160 <fixed_test+0x20>
test   %r14d,%r14d
jg     11b4 <fixed_test+0x74>
jmp    11d4 <fixed_test+0x94>
mov    $0xc350,%r14d
add    $0x1,%r14
nopl   0x0(%rax,%rax,1)
mov    -0x10(%rsp,%r14,8),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%r14
cmp    $0x1,%r14
ja     11c0 <fixed_test+0x80>
add    $0x61a80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"byte not cleared (size %d, element %d, byte %d)\00"
define void @fixed_test(i32 %0) {
%2 = alloca i32
%3 = alloca [50000 x i8*]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %57, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 50000
br i1 %8, label %9, label %60
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call i64 @calloc(i32 1, i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %14
store i8* %12, i8** %15
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %9
br label %60
22: ; preds = %9
store i32 0, i32* %5
br label %23
23: ; preds = %53, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %56
27: ; preds = %23
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %27
%39 = load i32, i32* @stderr
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %40, i32 %41, i32 %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %27
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 -1, i8* %52
br label %53
53: ; preds = %45
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %23
56: ; preds = %23
br label %57
57: ; preds = %56
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %6
60: ; preds = %21, %6
br label %61
61: ; preds = %65, %60
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
%64 = icmp sgt i32 %62, 0
br i1 %64, label %65, label %71
65: ; preds = %61
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @free(i8* %69)
br label %61
71: ; preds = %61
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"byte not cleared (size %d, element %d, byte %d)\00"
define void @fixed_test(i32 %0) {
%2 = alloca [50000 x i8*]
%3 = bitcast [50000 x i8*]* %2 to i8*
%4 = icmp sgt i32 %0, 0
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %1, %27
%7 = phi i64 [ 0, %1 ], [ %28, %27 ]
%8 = tail call i64 @calloc(i32 1, i32 %0)
%9 = inttoptr i64 %8 to i8*
%10 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %2, i64 0, i64 %7
store i8* %9, i8** %10
%11 = icmp eq i64 %8, 0
br i1 %11, label %30, label %12
12: ; preds = %6
br i1 %4, label %13, label %27
13: ; preds = %12, %24
%14 = phi i64 [ %25, %24 ], [ 0, %12 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = trunc i64 %7 to i32
%20 = trunc i64 %14 to i32
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %19, i32 %20)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %13
store i8 -1, i8* %15
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %13
27: ; preds = %24, %12
%28 = add nuw nsw i64 %7, 1
%29 = icmp eq i64 %28, 50000
br i1 %29, label %33, label %6
30: ; preds = %6
%31 = trunc i64 %7 to i32
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %27, %30
%34 = phi i64 [ %7, %30 ], [ 50000, %27 ]
%35 = and i64 %34, 4294967295
br label %36
36: ; preds = %33, %36
%37 = phi i64 [ %35, %33 ], [ %38, %36 ]
%38 = add nsw i64 %37, -1
%39 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %2, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = tail call i32 @free(i8* %40)
%42 = icmp ugt i64 %37, 1
br i1 %42, label %36, label %43
43: ; preds = %36, %30
ret void
}