#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 *);
int getnextdigit(void) {
  int n;
  while (0 == 0) {
    printf("Give me a number (-1 to quit): ");
    scanf("%d", &n);
    if (-1 <= n && 1 >= n) {
      break;
    }
    printf("I need a number that's either 0 or 1.\n");
  }
  return n;
}


x86 assembly (clang, -O0):
<getnextdigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    $0xffffffff,%eax
cmp    -0x4(%rbp),%eax
jg     1165 <getnextdigit+0x45>
mov    $0x1,%eax
cmp    -0x4(%rbp),%eax
jl     1165 <getnextdigit+0x45>
jmp    1176 <getnextdigit+0x56>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
jmp    1128 <getnextdigit+0x8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnextdigit>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
cmp    $0x3,%ecx
jb     11a7 <getnextdigit+0x77>
lea    0xebb(%rip),%r14
lea    0xe91(%rip),%r15
lea    0xeaa(%rip),%r12
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
ja     1180 <getnextdigit+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Give me a number (-1 to quit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"I need a number that's either 0 or 1.\0A\00"
define i32 @getnextdigit() {
%1 = alloca i32
br label %2
2: ; preds = %0, %11
%3 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sle i32 -1, %5
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* %1
%9 = icmp sge i32 1, %8
br i1 %9, label %10, label %11
10: ; preds = %7
br label %13
11: ; preds = %7, %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %2
13: ; preds = %10
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@.str = [32 x i8] c"Give me a number (-1 to quit): \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [38 x i8] c"I need a number that's either 0 or 1.\00"
define i32 @getnextdigit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add i32 %5, 1
%7 = icmp ult i32 %6, 3
br i1 %7, label %15, label %8
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = add i32 %12, 1
%14 = icmp ult i32 %13, 3
br i1 %14, label %15, label %8
15: ; preds = %8, %0
%16 = phi i32 [ %5, %0 ], [ %12, %8 ]
ret i32 %16
}