#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 __llair_choice();
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int main() {
  int c = __llair_choice() % 5;
  int *p;
  if (c) {
    p = (int *)malloc(sizeof(int));
  }
  for (int i = 0; i < 4; i++) {
    c += (__llair_choice() % 3);
  }
  if (c) {
    *p = 0;
    free(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <__llair_choice@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1169 <main+0x39>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    119d <main+0x6d>
mov    $0x0,%al
call   1050 <__llair_choice@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    -0x8(%rbp),%edx
mov    %edx,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <main+0x40>
cmpl   $0x0,-0x8(%rbp)
je     11ba <main+0x8a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <__llair_choice@plt>
movslq %eax,%r15
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
je     116a <main+0x3a>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
jmp    116a <main+0x3a>
xor    %eax,%eax
call   1050 <__llair_choice@plt>
movslq %eax,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
add    %r15d,%ebx
xor    %eax,%eax
call   1050 <__llair_choice@plt>
movslq %eax,%r15
imul   $0x55555556,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%r15d
add    %ebx,%r15d
xor    %eax,%eax
call   1050 <__llair_choice@plt>
movslq %eax,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
add    %r15d,%ebx
xor    %eax,%eax
call   1050 <__llair_choice@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
add    %ebx,%eax
je     1212 <main+0xe2>
movl   $0x0,(%r14)
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @__llair_choice()
%6 = srem i32 %5, 5
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i64 @malloc(i32 4)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
br label %12
12: ; preds = %9, %0
store i32 0, i32* %4
br label %13
13: ; preds = %21, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = call i32 (...) @__llair_choice()
%18 = srem i32 %17, 3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, %18
store i32 %20, i32* %2
br label %21
21: ; preds = %16
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %13
24: ; preds = %13
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32*, i32** %3
store i32 0, i32* %28
%29 = load i32*, i32** %3
%30 = call i32 @free(i32* %29)
br label %31
31: ; preds = %27, %24
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @__llair_choice()
%2 = srem i32 %1, 5
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
br label %7
7: ; preds = %4, %0
%8 = phi i32* [ %6, %4 ], [ undef, %0 ]
%9 = tail call i32 (...) @__llair_choice()
%10 = srem i32 %9, 3
%11 = add nsw i32 %10, %2
%12 = tail call i32 (...) @__llair_choice()
%13 = srem i32 %12, 3
%14 = add nsw i32 %13, %11
%15 = tail call i32 (...) @__llair_choice()
%16 = srem i32 %15, 3
%17 = add nsw i32 %16, %14
%18 = tail call i32 (...) @__llair_choice()
%19 = srem i32 %18, 3
%20 = sub nsw i32 0, %17
%21 = icmp eq i32 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %7
store i32 0, i32* %8
%23 = tail call i32 @free(i32* %8)
br label %24
24: ; preds = %22, %7
ret i32 0
}