#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 *);
int random();
void random_test(void) {
  char *ptrs[50000];
  int i;
  for (i = 0; i < 50000; ++i) {
    int j;
    int n = 1 + random() % 10;
    int elem = 1 + random() % 100;
    int size = n * elem;
    ptrs[i] = (char *)calloc(n, elem);
    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):
<random_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x61a84(%rbp)
cmpl   $0xc350,-0x61a84(%rbp)
jge    1297 <random_test+0x157>
mov    $0x0,%al
call   1050 <random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x61a8c(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x61a90(%rbp)
mov    -0x61a8c(%rbp),%eax
imul   -0x61a90(%rbp),%eax
mov    %eax,-0x61a94(%rbp)
mov    -0x61a8c(%rbp),%edi
mov    -0x61a90(%rbp),%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
movslq -0x61a84(%rbp),%rax
mov    %rcx,-0x61a80(%rbp,%rax,8)
ff
movslq -0x61a84(%rbp),%rax
cmpq   $0x0,-0x61a80(%rbp,%rax,8)
jne    11e6 <random_test+0xa6>
jmp    1297 <random_test+0x157>
movl   $0x0,-0x61a88(%rbp)
mov    -0x61a88(%rbp),%eax
cmp    -0x61a94(%rbp),%eax
jge    127e <random_test+0x13e>
movslq -0x61a84(%rbp),%rax
mov    -0x61a80(%rbp,%rax,8),%rax
ff
movslq -0x61a88(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1250 <random_test+0x110>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x61a94(%rbp),%ecx
mov    -0x61a84(%rbp),%r8d
mov    -0x61a88(%rbp),%r9d
xor    %esi,%esi
lea    0xdb5(%rip),%rdx
call   1060 <error@plt>
movslq -0x61a84(%rbp),%rax
mov    -0x61a80(%rbp,%rax,8),%rax
ff
movslq -0x61a88(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x61a88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a88(%rbp)
jmp    11f0 <random_test+0xb0>
jmp    1283 <random_test+0x143>
mov    -0x61a84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a84(%rbp)
jmp    1155 <random_test+0x15>
jmp    129c <random_test+0x15c>
mov    -0x61a84(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x61a84(%rbp)
cmp    $0x0,%eax
jle    12cf <random_test+0x18f>
movslq -0x61a84(%rbp),%rax
mov    -0x61a80(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
jmp    129c <random_test+0x15c>
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61a88,%rsp
lea    0xea8(%rip),%r14
xor    %r15d,%r15d
jmp    1171 <random_test+0x31>
nopl   (%rax)
add    $0x1,%r15
cmp    $0xc350,%r15
je     1235 <random_test+0xf5>
xor    %eax,%eax
call   1050 <random@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r12d
add    $0x1,%r12d
xor    %eax,%eax
call   1050 <random@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r13d
add    $0x1,%r13d
mov    %r12d,%edi
mov    %r13d,%esi
call   1040 <calloc@plt>
mov    %rax,(%rsp,%r15,8)
test   %rax,%rax
je     123d <random_test+0xfd>
imul   %r12d,%r13d
test   %r13d,%r13d
jle    1160 <random_test+0x20>
mov    %rax,%rbx
mov    %r13d,%r12d
xor    %ebp,%ebp
jmp    1211 <random_test+0xd1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0xff,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1160 <random_test+0x20>
cmpb   $0x0,(%rbx,%rbp,1)
je     1200 <random_test+0xc0>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %ebp,%r9d
call   1060 <error@plt>
jmp    1200 <random_test+0xc0>
mov    $0xc350,%r15d
jmp    1242 <random_test+0x102>
test   %r15d,%r15d
jle    1264 <random_test+0x124>
add    $0x1,%r15
cs nopw 0x0(%rax,%rax,1)
mov    -0x10(%rsp,%r15,8),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%r15
cmp    $0x1,%r15
ja     1250 <random_test+0x110>
add    $0x61a88,%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 @random_test() {
%1 = alloca [50000 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %2
br label %7
7: ; preds = %67, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 50000
br i1 %9, label %10, label %70
10: ; preds = %7
%11 = call i32 (...) @random()
%12 = srem i32 %11, 10
%13 = add nsw i32 1, %12
store i32 %13, i32* %4
%14 = call i32 (...) @random()
%15 = srem i32 %14, 100
%16 = add nsw i32 1, %15
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i64 @calloc(i32 %20, i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %25
store i8* %23, i8** %26
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %10
br label %70
33: ; preds = %10
store i32 0, i32* %3
br label %34
34: ; preds = %63, %33
%35 = load i32, i32* %3
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %66
38: ; preds = %34
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %38
%50 = load i32, i32* @EXIT_FAILURE
%51 = load i32, i32* %6
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = call i32 @error(i32 %50, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %49, %38
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %57
%59 = load i8*, i8** %58
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 -1, i8* %62
br label %63
63: ; preds = %55
%64 = load i32, i32* %3
%65 = add nsw i32 %64, 1
store i32 %65, i32* %3
br label %34
66: ; preds = %34
br label %67
67: ; preds = %66
%68 = load i32, i32* %2
%69 = add nsw i32 %68, 1
store i32 %69, i32* %2
br label %7
70: ; preds = %32, %7
br label %71
71: ; preds = %75, %70
%72 = load i32, i32* %2
%73 = add nsw i32 %72, -1
store i32 %73, i32* %2
%74 = icmp sgt i32 %72, 0
br i1 %74, label %75, label %81
75: ; preds = %71
%76 = load i32, i32* %2
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @free(i8* %79)
br label %71
81: ; preds = %71
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 @random_test() {
%1 = alloca [50000 x i8*]
%2 = bitcast [50000 x i8*]* %1 to i8*
br label %3
3: ; preds = %0, %33
%4 = phi i64 [ 0, %0 ], [ %34, %33 ]
%5 = tail call i32 (...) @random()
%6 = srem i32 %5, 10
%7 = add nsw i32 %6, 1
%8 = tail call i32 (...) @random()
%9 = srem i32 %8, 100
%10 = add nsw i32 %9, 1
%11 = mul nsw i32 %10, %7
%12 = tail call i64 @calloc(i32 %7, i32 %10)
%13 = inttoptr i64 %12 to i8*
%14 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %4
store i8* %13, i8** %14
%15 = icmp eq i64 %12, 0
%16 = trunc i64 %4 to i32
br i1 %15, label %36, label %17
17: ; preds = %3
%18 = icmp sgt i32 %11, 0
br i1 %18, label %19, label %33
19: ; preds = %17
%20 = zext i32 %11 to i64
br label %21
21: ; preds = %19, %30
%22 = phi i64 [ 0, %19 ], [ %31, %30 ]
%23 = getelementptr inbounds i8, i8* %13, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i32, i32* @EXIT_FAILURE
%28 = trunc i64 %22 to i32
%29 = tail call i32 @error(i32 %27, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %16, i32 %28)
br label %30
30: ; preds = %26, %21
store i8 -1, i8* %23
%31 = add nuw nsw i64 %22, 1
%32 = icmp eq i64 %31, %20
br i1 %32, label %33, label %21
33: ; preds = %30, %17
%34 = add nuw nsw i64 %4, 1
%35 = icmp eq i64 %34, 50000
br i1 %35, label %39, label %3
36: ; preds = %3
%37 = trunc i64 %4 to i32
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %33, %36
%40 = phi i64 [ %4, %36 ], [ 50000, %33 ]
%41 = and i64 %40, 4294967295
br label %42
42: ; preds = %39, %42
%43 = phi i64 [ %41, %39 ], [ %44, %42 ]
%44 = add nsw i64 %43, -1
%45 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %1, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = tail call i32 @free(i8* %46)
%48 = icmp ugt i64 %43, 1
br i1 %48, label %42, label %49
49: ; preds = %42, %36
ret void
}