#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 *binarystr(unsigned short);
int /*<<< orphan*/ printf(char *, ...);
unsigned short randomunsignedshort();
unsigned short readunsignedshort(char *);
void testoctal() {
  printf("Testing Understanding of Binary and Octal Patterns\n");
  int i, correct = 0;
  for (i = 0; i < 8; i++) {
    unsigned short sval = randomunsignedshort();
    printf("Binary Value: %s\n", binarystr(sval));
    unsigned short sentry = readunsignedshort("Enter Octal: ");
    if (sentry == sval)
      printf("Correct\n");
    else
      printf("Incorrect\n");
  }
}


x86 assembly (clang, -O0):
<testoctal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x8,-0x4(%rbp)
jge    11e7 <testoctal+0xa7>
mov    $0x0,%al
call   1040 <randomunsignedshort@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%edi
call   1060 <binarystr@plt>
mov    %rax,%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
call   1050 <readunsignedshort@plt>
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jne    11c6 <testoctal+0x86>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d4 <testoctal+0x94>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d9 <testoctal+0x99>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1164 <testoctal+0x24>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testoctal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebx
mov    %ebx,%edi
call   1070 <binarystr@plt>
lea    0xe84(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe82(%rip),%r15
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
lea    0xebb(%rip),%r12
lea    0xeaa(%rip),%rbx
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%ebp
mov    %ebp,%edi
call   1070 <binarystr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
cmove  %r12,%rbx
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Testing Understanding of Binary and Octal Patterns\0A\00"
@.str.1 = [18 x i8] c"Binary Value: %s\0A\00"
@.str.2 = [14 x i8] c"Enter Octal: \00"
@.str.3 = [9 x i8] c"Correct\0A\00"
@.str.4 = [11 x i8] c"Incorrect\0A\00"
define void @testoctal() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i16
%4 = alloca i16
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %1
br label %6
6: ; preds = %25, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = call zeroext i16 (...) @randomunsignedshort()
store i16 %10, i16* %3
%11 = load i16, i16* %3
%12 = call i8* @binarystr(i16 zeroext %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i16 %14, i16* %4
%15 = load i16, i16* %4
%16 = zext i16 %15 to i32
%17 = load i16, i16* %3
%18 = zext i16 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %24
22: ; preds = %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
br label %25
25: ; preds = %24
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Binary Value: %s\0A\00"
@.str.2 = [14 x i8] c"Enter Octal: \00"
@str = [51 x i8] c"Testing Understanding of Binary and Octal Patterns\00"
@str.5 = [10 x i8] c"Incorrect\00"
@str.6 = [8 x i8] c"Correct\00"
define void @testoctal() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%2 = tail call zeroext i16 (...) @randomunsignedshort()
%3 = tail call i8* @binarystr(i16 zeroext %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i16 %5, %2
%7 = select i1 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
%9 = tail call zeroext i16 (...) @randomunsignedshort()
%10 = tail call i8* @binarystr(i16 zeroext %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i16 %12, %9
%14 = select i1 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
%16 = tail call zeroext i16 (...) @randomunsignedshort()
%17 = tail call i8* @binarystr(i16 zeroext %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i16 %19, %16
%21 = select i1 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = tail call zeroext i16 (...) @randomunsignedshort()
%24 = tail call i8* @binarystr(i16 zeroext %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i16 %26, %23
%28 = select i1 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
%30 = tail call zeroext i16 (...) @randomunsignedshort()
%31 = tail call i8* @binarystr(i16 zeroext %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i16 %33, %30
%35 = select i1 %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%36 = tail call i32 @puts(i8* dereferenceable(1) %35)
%37 = tail call zeroext i16 (...) @randomunsignedshort()
%38 = tail call i8* @binarystr(i16 zeroext %37)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i16 %40, %37
%42 = select i1 %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%43 = tail call i32 @puts(i8* dereferenceable(1) %42)
%44 = tail call zeroext i16 (...) @randomunsignedshort()
%45 = tail call i8* @binarystr(i16 zeroext %44)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq i16 %47, %44
%49 = select i1 %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%50 = tail call i32 @puts(i8* dereferenceable(1) %49)
%51 = tail call zeroext i16 (...) @randomunsignedshort()
%52 = tail call i8* @binarystr(i16 zeroext %51)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp eq i16 %54, %51
%56 = select i1 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%57 = tail call i32 @puts(i8* dereferenceable(1) %56)
ret void
}