#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 *, char *, char *);
int main() {
  char resp, enter;
  int legal;
  printf("do-while Loop Example 4\n\n");
  do {
    printf("Please enter either A, B or C: ");
    scanf("%c%c", &resp, &enter);
    if (resp != 'A' && resp != 'B' && resp != 'C')
      printf("Invalid response, try again.\n");
  } while (resp != 'A' && resp != 'B' && resp != 'C');
  printf("Your valid entry was %c.\n\n", resp);
  legal = 0;
  do {
    printf("Please enter either A, B or C: ");
    scanf("%c%c", &resp, &enter);
    if (resp != 'A' && resp != 'B' && resp != 'C')
      printf("Invalid response, try again.\n");
    else
      legal = 1;
  } while (legal == 0);
  printf("Your valid entry was %c.\n\n", resp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
je     1194 <main+0x74>
movsbl -0x5(%rbp),%eax
cmp    $0x42,%eax
je     1194 <main+0x74>
movsbl -0x5(%rbp),%eax
cmp    $0x43,%eax
je     1194 <main+0x74>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1199 <main+0x79>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0xd(%rbp)
je     11ca <main+0xaa>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x42,%ecx
mov    %al,-0xd(%rbp)
je     11ca <main+0xaa>
movsbl -0x5(%rbp),%eax
cmp    $0x43,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    113d <main+0x1d>
movsbl -0x5(%rbp),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe37(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
je     124a <main+0x12a>
movsbl -0x5(%rbp),%eax
cmp    $0x42,%eax
je     124a <main+0x12a>
movsbl -0x5(%rbp),%eax
cmp    $0x43,%eax
je     124a <main+0x12a>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1251 <main+0x131>
movl   $0x1,-0xc(%rbp)
jmp    1256 <main+0x136>
cmpl   $0x0,-0xc(%rbp)
je     11ee <main+0xce>
movsbl -0x5(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%r14
lea    0xec9(%rip),%r15
lea    0xe(%rsp),%r12
lea    0xf(%rsp),%rbx
lea    0xef1(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <scanf@plt>
movzbl 0xe(%rsp),%eax
lea    -0x44(%rax),%ecx
cmp    $0xfc,%cl
ja     11aa <main+0x7a>
mov    %r13,%rdi
call   1030 <puts@plt>
movzbl 0xe(%rsp),%eax
lea    -0x44(%rax),%ecx
cmp    $0xfd,%cl
jb     1170 <main+0x40>
movzbl %al,%esi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xe(%rsp),%rsi
lea    0xf(%rsp),%rdx
call   1050 <scanf@plt>
mov    0xe(%rsp),%al
lea    -0x44(%rax),%ecx
cmp    $0xfc,%cl
ja     123d <main+0x10d>
lea    0xe67(%rip),%r14
lea    0xe07(%rip),%r15
lea    0xe20(%rip),%r12
lea    0xe(%rsp),%r13
lea    0xf(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <scanf@plt>
movzbl 0xe(%rsp),%eax
lea    -0x44(%rax),%ecx
cmp    $0xfd,%cl
jb     1210 <main+0xe0>
movzbl %al,%esi
lea    0xdde(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"do-while Loop Example 4\0A\0A\00"
@.str.1 = [32 x i8] c"Please enter either A, B or C: \00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.3 = [30 x i8] c"Invalid response, try again.\0A\00"
@.str.4 = [27 x i8] c"Your valid entry was %c.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %35, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %3)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 65
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 66
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 67
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %16, %12, %6
br label %23
23: ; preds = %22
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 65
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 66
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i8, i8* %2
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 67
br label %35
35: ; preds = %31, %27, %23
%36 = phi i1 [ false, %27 ], [ false, %23 ], [ %34, %31 ]
br i1 %36, label %6, label %37
37: ; preds = %35
%38 = load i8, i8* %2
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %39)
store i32 0, i32* %4
br label %41
41: ; preds = %59, %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %3)
%44 = load i8, i8* %2
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 65
br i1 %46, label %47, label %57
47: ; preds = %41
%48 = load i8, i8* %2
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 66
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = load i8, i8* %2
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 67
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %58
57: ; preds = %51, %47, %41
store i32 1, i32* %4
br label %58
58: ; preds = %57, %55
br label %59
59: ; preds = %58
%60 = load i32, i32* %4
%61 = icmp eq i32 %60, 0
br i1 %61, label %41, label %62
62: ; preds = %59
%63 = load i8, i8* %2
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %64)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"Please enter either A, B or C: \00"
@.str.2 = [5 x i8] c"%c%c\00"
@.str.4 = [27 x i8] c"Your valid entry was %c.\0A\0A\00"
@str = [25 x i8] c"do-while Loop Example 4\0A\00"
@str.6 = [29 x i8] c"Invalid response, try again.\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %10, %0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%7 = load i8, i8* %1
%8 = add i8 %7, -68
%9 = icmp ult i8 %8, -3
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%12 = load i8, i8* %1
%13 = add i8 %12, -68
%14 = icmp ult i8 %13, -3
br i1 %14, label %4, label %15
15: ; preds = %4, %10
%16 = phi i8 [ %12, %10 ], [ %7, %4 ]
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%21 = load i8, i8* %1
%22 = add i8 %21, -68
%23 = icmp ult i8 %22, -3
br i1 %23, label %24, label %31
24: ; preds = %15, %24
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%28 = load i8, i8* %1
%29 = add i8 %28, -68
%30 = icmp ult i8 %29, -3
br i1 %30, label %24, label %31
31: ; preds = %24, %15
%32 = phi i8 [ %21, %15 ], [ %28, %24 ]
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %33)
ret i32 0
}