#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*/ assert(int);
int atf_freebloc(void *);
int /*<<< orphan*/ atf_init();
void *atf_newbloc();
int rand();
int main() {
  void *addr[42];
  int naddr = 0;
  void *p;
  int i, status;
  atf_init();
  while ((p = atf_newbloc())) {
    if (naddr < 42 && (rand() % 4 == 0))
      addr[naddr++] = p;
  }
  for (i = 0; i < naddr; i++) {
    status = atf_freebloc(addr[i]);
    assert(status == 0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x164(%rbp)
mov    $0x0,%al
call   1040 <atf_init@plt>
mov    $0x0,%al
call   1050 <atf_newbloc@plt>
mov    %rax,-0x170(%rbp)
cmp    $0x0,%rax
je     11d7 <main+0x87>
cmpl   $0x2a,-0x164(%rbp)
jge    11d2 <main+0x82>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d2 <main+0x82>
mov    -0x170(%rbp),%rcx
mov    -0x164(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x164(%rbp)
cltq
mov    %rcx,-0x160(%rbp,%rax,8)
ff
jmp    1173 <main+0x23>
movl   $0x0,-0x174(%rbp)
mov    -0x174(%rbp),%eax
cmp    -0x164(%rbp),%eax
jge    1235 <main+0xe5>
movslq -0x174(%rbp),%rax
mov    -0x160(%rbp,%rax,8),%rdi
ff
call   1060 <atf_freebloc@plt>
mov    %eax,-0x178(%rbp)
cmpl   $0x0,-0x178(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x174(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x174(%rbp)
jmp    11e1 <main+0x91>
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x158,%rsp
xor    %eax,%eax
call   1040 <atf_init@plt>
xor    %eax,%eax
call   1050 <atf_newbloc@plt>
test   %rax,%rax
je     11df <main+0x8f>
mov    %rax,%rbx
xor    %ebp,%ebp
jmp    118f <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <atf_newbloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ab <main+0x5b>
cmp    $0x29,%ebp
jg     1180 <main+0x30>
xor    %eax,%eax
call   1070 <rand@plt>
test   $0x3,%al
jne    1180 <main+0x30>
movslq %ebp,%rax
add    $0x1,%ebp
mov    %rbx,(%rsp,%rax,8)
jmp    1180 <main+0x30>
test   %ebp,%ebp
jle    11df <main+0x8f>
mov    %ebp,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp,%rbp,8),%rdi
call   1060 <atf_freebloc@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <main+0x70>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [42 x i8*]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 (...) @atf_init()
br label %8
8: ; preds = %24, %0
%9 = call i8* (...) @atf_newbloc()
store i8* %9, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 42
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [42 x i8*], [42 x i8*]* %2, i64 0, i64 %22
store i8* %19, i8** %23
br label %24
24: ; preds = %18, %14, %11
br label %8
25: ; preds = %8
store i32 0, i32* %5
br label %26
26: ; preds = %40, %25
%27 = load i32, i32* %5
%28 = load i32, i32* %3
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [42 x i8*], [42 x i8*]* %2, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @atf_freebloc(i8* %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
br label %40
40: ; preds = %30
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %26
43: ; preds = %26
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [42 x i8*]
%2 = bitcast [42 x i8*]* %1 to i8*
%3 = tail call i32 (...) @atf_init()
%4 = tail call i8* (...) @atf_newbloc()
%5 = icmp eq i8* %4, null
br i1 %5, label %36, label %10
6: ; preds = %22
%7 = icmp sgt i32 %23, 0
br i1 %7, label %8, label %36
8: ; preds = %6
%9 = zext i32 %23 to i64
br label %26
10: ; preds = %0, %22
%11 = phi i8* [ %24, %22 ], [ %4, %0 ]
%12 = phi i32 [ %23, %22 ], [ 0, %0 ]
%13 = icmp slt i32 %12, 42
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = tail call i32 (...) @rand()
%16 = and i32 %15, 3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = add nsw i32 %12, 1
%20 = sext i32 %12 to i64
%21 = getelementptr inbounds [42 x i8*], [42 x i8*]* %1, i64 0, i64 %20
store i8* %11, i8** %21
br label %22
22: ; preds = %18, %14, %10
%23 = phi i32 [ %19, %18 ], [ %12, %14 ], [ %12, %10 ]
%24 = tail call i8* (...) @atf_newbloc()
%25 = icmp eq i8* %24, null
br i1 %25, label %6, label %10
26: ; preds = %8, %26
%27 = phi i64 [ 0, %8 ], [ %34, %26 ]
%28 = getelementptr inbounds [42 x i8*], [42 x i8*]* %1, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @atf_freebloc(i8* %29)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = add nuw nsw i64 %27, 1
%35 = icmp eq i64 %34, %9
br i1 %35, label %36, label %26
36: ; preds = %26, %0, %6
ret i32 0
}