#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 */
typedef int /*<<< orphan*/ arrays;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sched_yield();
void *func(void *p) {
  int *counter = (int *)p;
  unsigned i;
  enum { numarrays = 100, numels = 17 };
  char *arrays[numarrays];
  for (i = 0; i < numarrays; i++) {
    (*counter)++;
    unsigned x = i % numels;
    arrays[i] = calloc(numels, sizeof(arrays[i][0]));
    assert(arrays[i] != NULL);
    arrays[i][x] = i;
    free(arrays[i]);
    sched_yield();
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jae    11f9 <func+0xb9>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    $0x11,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x344(%rbp)
mov    $0x11,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
mov    %rcx,-0x340(%rbp,%rax,8)
ff
mov    -0x14(%rbp),%eax
cmpq   $0x0,-0x340(%rbp,%rax,8)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x14(%rbp),%eax
mov    -0x340(%rbp,%rax,8),%rax
ff
mov    -0x344(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    -0x340(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    $0x0,%al
call   1040 <sched_yield@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <func+0x1e>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
movabs $0xf0f0f0f0f0f0f0f1,%r12
f0 f0 f0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
mul    %r12
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x4,%rax
add    %rdx,%rax
mov    %rbx,%r13
sub    %rax,%r13
addl   $0x1,(%r14)
mov    $0x11,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %bl,(%r15,%r13,1)
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1040 <sched_yield@plt>
add    $0x1,%rbx
cmp    $0x64,%ebx
jne    1160 <func+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @func(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %17, %3 ]
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %2
%7 = trunc i32 %4 to i8
%8 = urem i8 %7, 17
%9 = tail call dereferenceable_or_null(17) i8* @calloc(i32 17, i32 1)
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = zext i8 %8 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
store i8 %7, i8* %14
%15 = tail call i32 @free(i8* %9)
%16 = tail call i32 (...) @sched_yield()
%17 = add nuw nsw i32 %4, 1
%18 = icmp eq i32 %17, 100
br i1 %18, label %19, label %3
19: ; preds = %3
ret i8* null
}