#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 cancelBooking(int seats[], int arrayLength) {
  int seatNumber;
  printf("Give the number of the seat you want to cancel\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) {
      printf("The number of the seat you have given is not booked\n");
    } else {
      seats[seatNumber - 1] = 0;
      printf("Your booking (seat number %d) is canceled\n", seatNumber);
    }
  }
}


x86 assembly (clang, -O0):
<cancelBooking>:
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    0xeec(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1163 <cancelBooking+0x43>
cmpl   $0x0,-0x10(%rbp)
jg     1176 <cancelBooking+0x56>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <cancelBooking+0xaa>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11a0 <cancelBooking+0x80>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <cancelBooking+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <cancelBooking+0xaa>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cancelBooking>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeef(%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     1181 <cancelBooking+0x51>
test   %esi,%esi
jle    1181 <cancelBooking+0x51>
lea    -0x1(%rsi),%eax
cmpl   $0x0,(%rbx,%rax,4)
je     118a <cancelBooking+0x5a>
movl   $0x0,(%rbx,%rax,4)
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1196 <cancelBooking+0x66>
lea    0xf09(%rip),%rdi
jmp    1191 <cancelBooking+0x61>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Give the number of the seat you want to cancel\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 = [53 x i8] c"The number of the seat you have given is not booked\0A\00"
@.str.4 = [43 x i8] c"Your booking (seat number %d) is canceled\0A\00"
define void @cancelBooking(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 ([48 x i8], [48 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 %35
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 %26
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %34
26: ; preds = %16
%27 = load i32*, i32** %3
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 0, i32* %31
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %26, %24
br label %35
35: ; preds = %34, %14
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [43 x i8] c"Your booking (seat number %d) is canceled\0A\00"
@str = [47 x i8] c"Give the number of the seat you want to cancel\00"
@str.5 = [52 x i8] c"The number of the seat you have given is not booked\00"
@str.6 = [53 x i8] c"The number of the seat you have given does not exist\00"
define void @cancelBooking(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 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.6, 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
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.5, i64 0, i64 0))
br label %23
21: ; preds = %13
store i32 0, i32* %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %7)
br label %23
23: ; preds = %19, %21, %11
ret void
}