#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 atoi(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int stock = 180;
  char order_string[3];
  int order;
  while (stock > 0) {
    printf("%i glasses left\n", stock);
    scanf("%2s", order_string);
    order = atoi(order_string);
    stock = stock - order;
    printf("You ordered %i glasses\n", order);
  }
  puts("We're out of stock, baby!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xb4,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11a8 <main+0x68>
mov    -0x8(%rbp),%esi
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1050 <scanf@plt>
lea    -0xb(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
jmp    1156 <main+0x16>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xb4,%ebx
lea    0xea9(%rip),%r14
lea    0xeb3(%rip),%r15
lea    0x5(%rsp),%r12
lea    0xeab(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
sub    %ebp,%ebx
jg     1170 <main+0x30>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%i glasses left\0A\00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [24 x i8] c"You ordered %i glasses\0A\00"
@.str.3 = [26 x i8] c"We're out of stock, baby!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 180, i32* %2
br label %5
5: ; preds = %8, %0
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = load i32, i32* %4
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %2
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %5
20: ; preds = %5
%21 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"%i glasses left\0A\00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [24 x i8] c"You ordered %i glasses\0A\00"
@.str.3 = [26 x i8] c"We're out of stock, baby!\00"
define i32 @main() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 180, %0 ], [ %8, %3 ]
%5 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = call i32 @atoi(i8* %2)
%8 = sub nsw i32 %4, %7
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %3, label %11
11: ; preds = %3
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}