#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(unsigned int, int);
int random_loss();
unsigned int *create_loss_array_from_markov_model(unsigned int size) {
  unsigned int *is_lost_array;
  unsigned int i;
  is_lost_array = (unsigned int *)calloc(size, sizeof(unsigned int));
  for (i = 0; i < size; i++) {
    if (random_loss() == 1)
      is_lost_array[i] = 1;
  }
  return is_lost_array;
}


x86 assembly (clang, -O0):
<create_loss_array_from_markov_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1180 <create_loss_array_from_markov_model+0x60>
mov    $0x0,%al
call   1030 <random_loss@plt>
cmp    $0x1,%eax
jne    116d <create_loss_array_from_markov_model+0x4d>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movl   $0x1,(%rax,%rcx,4)
jmp    1172 <create_loss_array_from_markov_model+0x52>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <create_loss_array_from_markov_model+0x23>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_loss_array_from_markov_model>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     115f <create_loss_array_from_markov_model+0x3f>
mov    %ebp,%ebp
xor    %ebx,%ebx
jmp    1149 <create_loss_array_from_markov_model+0x29>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     115f <create_loss_array_from_markov_model+0x3f>
xor    %eax,%eax
call   1030 <random_loss@plt>
cmp    $0x1,%eax
jne    1140 <create_loss_array_from_markov_model+0x20>
movl   $0x1,(%r14,%rbx,4)
jmp    1140 <create_loss_array_from_markov_model+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32* @create_loss_array_from_markov_model(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @calloc(i32 %5, i32 4)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %3
store i32 0, i32* %4
br label %8
8: ; preds = %21, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = call i32 (...) @random_loss()
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 1, i32* %19
br label %20
20: ; preds = %15, %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add i32 %22, 1
store i32 %23, i32* %4
br label %8
24: ; preds = %8
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
define i32* @create_loss_array_from_markov_model(i32 %0) {
%2 = tail call i64 @calloc(i32 %0, i32 4)
%3 = inttoptr i64 %2 to i32*
%4 = icmp eq i32 %0, 0
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %13
%8 = phi i64 [ 0, %5 ], [ %14, %13 ]
%9 = tail call i32 (...) @random_loss()
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = getelementptr inbounds i32, i32* %3, i64 %8
store i32 1, i32* %12
br label %13
13: ; preds = %7, %11
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %7
16: ; preds = %13, %1
ret i32* %3
}