#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 /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *, int,
                         int, int);
int /*<<< orphan*/ free(char *);
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')
        error(EXIT_FAILURE, 0,
              "byte not cleared (size %d, element %d, byte %d)", size, i, j);
      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    123d <fixed_test+0x10d>
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    1192 <fixed_test+0x62>
jmp    123d <fixed_test+0x10d>
movl   $0x0,-0x61a98(%rbp)
mov    -0x61a98(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1224 <fixed_test+0xf4>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,8),%rax
ff
movslq -0x61a98(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11f6 <fixed_test+0xc6>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%ecx
mov    -0x61a94(%rbp),%r8d
mov    -0x61a98(%rbp),%r9d
xor    %esi,%esi
lea    0xe0f(%rip),%rdx
call   1050 <error@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    119c <fixed_test+0x6c>
jmp    1229 <fixed_test+0xf9>
mov    -0x61a94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a94(%rbp)
jmp    1148 <fixed_test+0x18>
jmp    1242 <fixed_test+0x112>
mov    -0x61a94(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x61a94(%rbp)
cmp    $0x0,%eax
jle    1275 <fixed_test+0x145>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
jmp    1242 <fixed_test+0x112>
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61a98,%rsp
mov    %edi,%ebp
mov    %edi,%r13d
xor    %r12d,%r12d
mov    0x2e90(%rip),%r14
lea    0xea9(%rip),%r15
mov    %edi,0xc(%rsp)
jmp    1171 <fixed_test+0x41>
nopl   (%rax)
add    $0x1,%r12
cmp    $0xc350,%r12
mov    0xc(%rsp),%ebp
je     11cb <fixed_test+0x9b>
mov    $0x1,%edi
mov    %ebp,%esi
call   1040 <calloc@plt>
mov    %rax,0x10(%rsp,%r12,8)
test   %rax,%rax
je     11d3 <fixed_test+0xa3>
test   %ebp,%ebp
jle    1160 <fixed_test+0x30>
mov    %rax,%rbx
xor    %ebp,%ebp
jmp    11ad <fixed_test+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0xff,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1160 <fixed_test+0x30>
cmpb   $0x0,(%rbx,%rbp,1)
je     11a0 <fixed_test+0x70>
mov    (%r14),%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r13d,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
call   1050 <error@plt>
jmp    11a0 <fixed_test+0x70>
mov    $0xc350,%r12d
jmp    11d8 <fixed_test+0xa8>
test   %r12d,%r12d
jle    11f3 <fixed_test+0xc3>
add    $0x1,%r12
nopl   0x0(%rax)
mov    (%rsp,%r12,8),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
ja     11e0 <fixed_test+0xb0>
add    $0x61a98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = 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 = %56, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 50000
br i1 %8, label %9, label %59
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 %59
22: ; preds = %9
store i32 0, i32* %5
br label %23
23: ; preds = %52, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %55
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 %44
38: ; preds = %27
%39 = load i32, i32* @EXIT_FAILURE
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = call i32 @error(i32 %39, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %38, %27
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 -1, i8* %51
br label %52
52: ; preds = %44
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %23
55: ; preds = %23
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %6
59: ; preds = %21, %6
br label %60
60: ; preds = %64, %59
%61 = load i32, i32* %4
%62 = add nsw i32 %61, -1
store i32 %62, i32* %4
%63 = icmp sgt i32 %61, 0
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %3, i64 0, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @free(i8* %68)
br label %60
70: ; preds = %60
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = 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, %26
%7 = phi i64 [ 0, %1 ], [ %27, %26 ]
%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
%12 = trunc i64 %7 to i32
br i1 %11, label %29, label %13
13: ; preds = %6
br i1 %4, label %14, label %26
14: ; preds = %13, %23
%15 = phi i64 [ %24, %23 ], [ 0, %13 ]
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i32, i32* @EXIT_FAILURE
%21 = trunc i64 %15 to i32
%22 = tail call i32 @error(i32 %20, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %12, i32 %21)
br label %23
23: ; preds = %19, %14
store i8 -1, i8* %16
%24 = add nuw nsw i64 %15, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %14
26: ; preds = %23, %13
%27 = add nuw nsw i64 %7, 1
%28 = icmp eq i64 %27, 50000
br i1 %28, label %32, label %6
29: ; preds = %6
%30 = trunc i64 %7 to i32
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %26, %29
%33 = phi i64 [ %7, %29 ], [ 50000, %26 ]
%34 = and i64 %33, 4294967295
br label %35
35: ; preds = %32, %35
%36 = phi i64 [ %34, %32 ], [ %37, %35 ]
%37 = add nsw i64 %36, -1
%38 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %2, i64 0, i64 %37
%39 = load i8*, i8** %38
%40 = tail call i32 @free(i8* %39)
%41 = icmp ugt i64 %36, 1
br i1 %41, label %35, label %42
42: ; preds = %35, %29
ret void
}