#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 */
char getchar();
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, int *);
void pot_allocation(int history[][6], int day) {
  int pots = history[day - 1][2];
  int *pots_in;
  pots_in = &history[day - 1][4];
  while (1) {
    printf("Enter the number of pots to put inside the bay (max %d): ", pots);
    if (scanf("%d", pots_in) != 1 || *pots_in < 0 || *pots_in > pots) {
      printf("Please enter a digit between 0 and %d, try again.\n\n", pots);
      while (getchar() != '\n')
        ;
    } else {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<pot_allocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xeab(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11b9 <pot_allocation+0x89>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11b9 <pot_allocation+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x10(%rbp),%eax
jle    11e5 <pot_allocation+0xb5>
mov    -0x10(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11e0 <pot_allocation+0xb0>
jmp    11c8 <pot_allocation+0x98>
jmp    11ea <pot_allocation+0xba>
jmp    11ef <pot_allocation+0xbf>
jmp    1175 <pot_allocation+0x45>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pot_allocation>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
add    $0xffffffff,%esi
movslq %esi,%rax
lea    (%rax,%rax,2),%rax
mov    0x8(%rdi,%rax,8),%ebx
lea    (%rdi,%rax,8),%r14
add    $0x10,%r14
lea    0xeaa(%rip),%r15
lea    0xedd(%rip),%r12
lea    0xed9(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1195 <pot_allocation+0x65>
mov    (%r14),%eax
test   %eax,%eax
js     1195 <pot_allocation+0x65>
cmp    %ebx,%eax
jle    11ad <pot_allocation+0x7d>
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
nop
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <pot_allocation+0x70>
jmp    1170 <pot_allocation+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [58 x i8] c"Enter the number of pots to put inside the bay (max %d): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [52 x i8] c"Please enter a digit between 0 and %d, try again.\0A\0A\00"
define void @pot_allocation([6 x i32]* %0, i32 %1) {
%3 = alloca [6 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store [6 x i32]* %0, [6 x i32]** %3
store i32 %1, i32* %4
%7 = load [6 x i32]*, [6 x i32]** %3
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 %10
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %11, i64 0, i64 2
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = load [6 x i32]*, [6 x i32]** %3
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %14, i64 %17
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %18, i64 0, i64 4
store i32* %19, i32** %6
br label %20
20: ; preds = %2, %45
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %6
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %35, label %26
26: ; preds = %20
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = icmp slt i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = load i32, i32* %5
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %30, %26, %20
%36 = load i32, i32* %5
%37 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %42, %35
%39 = call signext i8 (...) @getchar()
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %38
br label %38
43: ; preds = %38
br label %45
44: ; preds = %30
br label %46
45: ; preds = %43
br label %20
46: ; preds = %44
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"Enter the number of pots to put inside the bay (max %d): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [52 x i8] c"Please enter a digit between 0 and %d, try again.\0A\0A\00"
define void @pot_allocation([6 x i32]* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 2
%6 = load i32, i32* %5
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 4
br label %8
8: ; preds = %19, %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %6)
%10 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
%15 = icmp sgt i32 %13, %6
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %22
17: ; preds = %12, %8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %19
19: ; preds = %19, %17
%20 = tail call signext i8 (...) @getchar()
%21 = icmp eq i8 %20, 10
br i1 %21, label %8, label %19
22: ; preds = %12
ret void
}