#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void bookSeat(int seats[], int arrayLength) {
  int seatNumber;
  printf("Give the number of the seat you want to book\n");
  scanf("%d", &seatNumber);
  if (seatNumber > arrayLength || seatNumber <= 0) {
    printf("The number of the seat you have given does not exist\n");
  } else {
    if (seats[seatNumber - 1] == 0) {
      seats[seatNumber - 1] = 1;
      printf("Seat number %d was successfully booked\n", seatNumber);
    } else {
      printf("Seat number %d is already booked. Please choose another seat.\n",
             seatNumber);
    }
  }
}


x86 assembly (clang, -O0):
<bookSeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1163 <bookSeat+0x43>
cmpl   $0x0,-0x10(%rbp)
jg     1176 <bookSeat+0x56>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cd <bookSeat+0xad>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b7 <bookSeat+0x97>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c8 <bookSeat+0xa8>
mov    -0x10(%rbp),%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cd <bookSeat+0xad>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bookSeat>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xf2b(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
cmp    %ebp,%esi
jg     1173 <bookSeat+0x43>
test   %esi,%esi
jle    1173 <bookSeat+0x43>
lea    -0x1(%rsi),%eax
cmpl   $0x0,(%rbx,%rax,4)
je     1181 <bookSeat+0x51>
lea    0xeba(%rip),%rdi
jmp    118f <bookSeat+0x5f>
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
jmp    1196 <bookSeat+0x66>
movl   $0x1,(%rbx,%rax,4)
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Give the number of the seat you want to book\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"The number of the seat you have given does not exist\0A\00"
@.str.3 = [40 x i8] c"Seat number %d was successfully booked\0A\00"
@.str.4 = [63 x i8] c"Seat number %d is already booked. Please choose another seat.\0A\00"
define void @bookSeat(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %36
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
store i32 1, i32* %29
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %35
32: ; preds = %16
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %24
br label %36
36: ; preds = %35, %14
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [40 x i8] c"Seat number %d was successfully booked\0A\00"
@.str.4 = [63 x i8] c"Seat number %d is already booked. Please choose another seat.\0A\00"
@str = [45 x i8] c"Give the number of the seat you want to book\00"
@str.5 = [53 x i8] c"The number of the seat you have given does not exist\00"
define void @bookSeat(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, %1
%9 = icmp slt i32 %7, 1
%10 = or i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.5, i64 0, i64 0))
br label %23
13: ; preds = %2
%14 = add nsw i32 %7, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
store i32 1, i32* %16
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 %7)
br label %23
23: ; preds = %19, %21, %11
ret void
}