#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*/ printf(char *, ...);
void bookFirstSeatAtWindow(int seats[], int arrayLength) {
  int i = 0;
  while (seats[i] != 0) {
    if (i % 2 == 0) {
      if (i + 5 < arrayLength) {
        i = i + 3;
      } else {
        i = i + 4;
      }
    } else {
      i++;
    }
  }
  if (i < arrayLength) {
    seats[i] = 1;
    printf("Seat number %d was successfully booked\n", i + 1);
  } else {
    printf("All seats at window are already booked\n");
  }
}


x86 assembly (clang, -O0):
<bookFirstSeatAtWindow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1185 <bookFirstSeatAtWindow+0x75>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1177 <bookFirstSeatAtWindow+0x67>
mov    -0x10(%rbp),%eax
add    $0x5,%eax
cmp    -0xc(%rbp),%eax
jge    1169 <bookFirstSeatAtWindow+0x59>
mov    -0x10(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <bookFirstSeatAtWindow+0x62>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <bookFirstSeatAtWindow+0x70>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <bookFirstSeatAtWindow+0x16>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <bookFirstSeatAtWindow+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c7 <bookFirstSeatAtWindow+0xb7>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bookFirstSeatAtWindow>:
cmpl   $0x0,(%rdi)
je     1172 <bookFirstSeatAtWindow+0x52>
xor    %eax,%eax
mov    $0x1,%r8d
nopl   (%rax)
mov    %eax,%edx
lea    0x5(%rdx),%eax
xor    %ecx,%ecx
cmp    %esi,%eax
setl   %cl
mov    $0x4,%eax
sub    %ecx,%eax
test   $0x1,%dl
cmovne %r8d,%eax
add    %edx,%eax
cmpl   $0x0,(%rdi,%rax,4)
jne    1130 <bookFirstSeatAtWindow+0x10>
mov    %eax,%ecx
cmp    %esi,%eax
jge    117a <bookFirstSeatAtWindow+0x5a>
movl   $0x1,(%rdi,%rcx,4)
add    $0x1,%eax
lea    0xe97(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
jmp    1040 <printf@plt>
xor    %ecx,%ecx
xor    %eax,%eax
cmp    %esi,%eax
jl     1158 <bookFirstSeatAtWindow+0x38>
lea    0xea7(%rip),%rdi
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [40 x i8] c"Seat number %d was successfully booked\0A\00"
@str = [39 x i8] c"All seats at window are already booked\00"
define void @bookFirstSeatAtWindow(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %13, %5 ], [ 0, %2 ]
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
%9 = add nuw nsw i32 %6, 5
%10 = icmp slt i32 %9, %1
%11 = select i1 %10, i32 3, i32 4
%12 = select i1 %8, i32 %11, i32 1
%13 = add nuw nsw i32 %6, %12
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %5
%19 = zext i32 %13 to i64
br label %20
20: ; preds = %18, %2
%21 = phi i64 [ 0, %2 ], [ %19, %18 ]
%22 = phi i32 [ 0, %2 ], [ %13, %18 ]
%23 = icmp slt i32 %22, %1
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = getelementptr inbounds i32, i32* %0, i64 %21
store i32 1, i32* %25
%26 = add nsw i32 %22, 1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %20
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
ret void
}