#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__ find_seat(int, int, int *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int sim(int num) {
  int seats[num];
  memset(seats, 0, sizeof(int) * num);
  int numFree = num;
  int numPeople = 0;
  while (find_seat(num, numFree, seats)) {
    numPeople++;
  }
  for (int i = 0; i < num; i++) {
    printf("%d ", seats[i] == 1);
  }
  printf("\n");
  return numPeople;
}


x86 assembly (clang, -O0):
<sim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%rdx
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <find_seat@plt>
cmp    $0x0,%rax
je     11a7 <sim+0x77>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1180 <sim+0x50>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <sim+0xba>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ae <sim+0x7e>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sim>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
mov    %edi,%r12d
mov    %rsp,%r14
lea    0xf(,%r12,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0x0(,%r15,4),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0xffffffff,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r15d,%esi
mov    %r14,%rdx
call   1040 <find_seat@plt>
add    $0x1,%r13d
test   %rax,%rax
jne    1190 <sim+0x50>
test   %r15d,%r15d
jle    11de <sim+0x9e>
lea    0xe4d(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %esi,%esi
cmpl   $0x1,(%r14,%rbx,4)
sete   %sil
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <sim+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @sim(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i32, i64 %9
store i64 %9, i64* %4
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = mul i64 4, %13
%15 = trunc i64 %14 to i32
%16 = call i32 @memset(i32* %11, i32 0, i32 %15)
%17 = load i32, i32* %2
store i32 %17, i32* %5
store i32 0, i32* %6
br label %18
18: ; preds = %23, %1
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = call i64 @find_seat(i32 %19, i32 %20, i32* %11)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %18
26: ; preds = %18
store i32 0, i32* %7
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %2
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %11, i64 %33
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 1
%37 = zext i1 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %27
42: ; preds = %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = load i8*, i8** %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @sim(i32 %0) {
%2 = zext i32 %0 to i64
%3 = alloca i32, i64 %2
%4 = shl i32 %0, 2
%5 = call i32 @memset(i32* %3, i32 0, i32 %4)
br label %6
6: ; preds = %6, %1
%7 = phi i32 [ 0, %1 ], [ %10, %6 ]
%8 = call i64 @find_seat(i32 %0, i32 %0, i32* %3)
%9 = icmp eq i64 %8, 0
%10 = add nuw nsw i32 %7, 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = icmp sgt i32 %0, 0
br i1 %12, label %15, label %13
13: ; preds = %15, %11
%14 = call i32 @putchar(i32 10)
ret i32 %7
15: ; preds = %11, %15
%16 = phi i64 [ %22, %15 ], [ 0, %11 ]
%17 = getelementptr inbounds i32, i32* %3, i64 %16
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 1
%20 = zext i1 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %2
br i1 %23, label %13, label %15
}