#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 *, ...);
unsigned short randomunsignedshort();
unsigned short readunsignedshort(char *, int /*<<< orphan*/);
void testands() {
  printf("Testing 'and' operations on bit patterns represented as octal\n");
  int i = 0;
  for (i = 0; i < 8; i++) {
    unsigned short one = randomunsignedshort();
    unsigned short two = randomunsignedshort();
    printf("%6ho & %6ho ", one, two);
    unsigned short guess = readunsignedshort(" = ", 0);
    unsigned short value = one & two;
    if (guess == value)
      printf("Correct\n");
    else
      printf("Incorrect\n");
  }
}


x86 assembly (clang, -O0):
<testands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x8,-0x4(%rbp)
jge    11ee <testands+0xbe>
mov    $0x0,%al
call   1040 <randomunsignedshort@plt>
mov    %ax,-0x6(%rbp)
mov    $0x0,%al
call   1040 <randomunsignedshort@plt>
mov    %ax,-0x8(%rbp)
movzwl -0x6(%rbp),%esi
movzwl -0x8(%rbp),%edx
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
xor    %esi,%esi
call   1050 <readunsignedshort@plt>
mov    %ax,-0xa(%rbp)
movzwl -0x6(%rbp),%eax
movzwl -0x8(%rbp),%ecx
and    %ecx,%eax
mov    %ax,-0xc(%rbp)
movzwl -0xa(%rbp),%eax
movzwl -0xc(%rbp),%ecx
cmp    %ecx,%eax
jne    11cd <testands+0x9d>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11db <testands+0xab>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e0 <testands+0xb0>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1154 <testands+0x24>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testands>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebp
and    %ebx,%ebp
movzwl %bx,%esi
lea    0xe88(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe84(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bp,%ax
lea    0xebc(%rip),%r12
lea    0xeab(%rip),%r13
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <randomunsignedshort@plt>
movzwl %ax,%edx
mov    %eax,%ebx
and    %ebp,%ebx
movzwl %bp,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <readunsignedshort@plt>
cmp    %bx,%ax
cmove  %r12,%r13
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"Testing 'and' operations on bit patterns represented as octal\0A\00"
@.str.1 = [13 x i8] c"%6ho & %6ho \00"
@.str.2 = [4 x i8] c" = \00"
@.str.3 = [9 x i8] c"Correct\0A\00"
@.str.4 = [11 x i8] c"Incorrect\0A\00"
define void @testands() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
store i32 0, i32* %1
br label %7
7: ; preds = %35, %0
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %38
10: ; preds = %7
%11 = call zeroext i16 (...) @randomunsignedshort()
store i16 %11, i16* %2
%12 = call zeroext i16 (...) @randomunsignedshort()
store i16 %12, i16* %3
%13 = load i16, i16* %2
%14 = zext i16 %13 to i32
%15 = load i16, i16* %3
%16 = zext i16 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %16)
%18 = call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i16 %18, i16* %4
%19 = load i16, i16* %2
%20 = zext i16 %19 to i32
%21 = load i16, i16* %3
%22 = zext i16 %21 to i32
%23 = and i32 %20, %22
%24 = trunc i32 %23 to i16
store i16 %24, i16* %5
%25 = load i16, i16* %4
%26 = zext i16 %25 to i32
%27 = load i16, i16* %5
%28 = zext i16 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %32
30: ; preds = %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %34
32: ; preds = %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %7
38: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"%6ho & %6ho \00"
@.str.2 = [4 x i8] c" = \00"
@str = [62 x i8] c"Testing 'and' operations on bit patterns represented as octal\00"
@str.5 = [10 x i8] c"Incorrect\00"
@str.6 = [8 x i8] c"Correct\00"
define void @testands() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%2 = tail call zeroext i16 (...) @randomunsignedshort()
%3 = tail call zeroext i16 (...) @randomunsignedshort()
%4 = zext i16 %2 to i32
%5 = zext i16 %3 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5)
%7 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%8 = and i16 %3, %2
%9 = icmp eq i16 %7, %8
%10 = select i1 %9, 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)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call zeroext i16 (...) @randomunsignedshort()
%13 = tail call zeroext i16 (...) @randomunsignedshort()
%14 = zext i16 %12 to i32
%15 = zext i16 %13 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15)
%17 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%18 = and i16 %13, %12
%19 = icmp eq i16 %17, %18
%20 = select i1 %19, 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)
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
%22 = tail call zeroext i16 (...) @randomunsignedshort()
%23 = tail call zeroext i16 (...) @randomunsignedshort()
%24 = zext i16 %22 to i32
%25 = zext i16 %23 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
%27 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%28 = and i16 %23, %22
%29 = icmp eq i16 %27, %28
%30 = select i1 %29, 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)
%31 = tail call i32 @puts(i8* dereferenceable(1) %30)
%32 = tail call zeroext i16 (...) @randomunsignedshort()
%33 = tail call zeroext i16 (...) @randomunsignedshort()
%34 = zext i16 %32 to i32
%35 = zext i16 %33 to i32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35)
%37 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%38 = and i16 %33, %32
%39 = icmp eq i16 %37, %38
%40 = select i1 %39, 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)
%41 = tail call i32 @puts(i8* dereferenceable(1) %40)
%42 = tail call zeroext i16 (...) @randomunsignedshort()
%43 = tail call zeroext i16 (...) @randomunsignedshort()
%44 = zext i16 %42 to i32
%45 = zext i16 %43 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
%47 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%48 = and i16 %43, %42
%49 = icmp eq i16 %47, %48
%50 = select i1 %49, 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)
%51 = tail call i32 @puts(i8* dereferenceable(1) %50)
%52 = tail call zeroext i16 (...) @randomunsignedshort()
%53 = tail call zeroext i16 (...) @randomunsignedshort()
%54 = zext i16 %52 to i32
%55 = zext i16 %53 to i32
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %55)
%57 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%58 = and i16 %53, %52
%59 = icmp eq i16 %57, %58
%60 = select i1 %59, 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)
%61 = tail call i32 @puts(i8* dereferenceable(1) %60)
%62 = tail call zeroext i16 (...) @randomunsignedshort()
%63 = tail call zeroext i16 (...) @randomunsignedshort()
%64 = zext i16 %62 to i32
%65 = zext i16 %63 to i32
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %64, i32 %65)
%67 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%68 = and i16 %63, %62
%69 = icmp eq i16 %67, %68
%70 = select i1 %69, 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)
%71 = tail call i32 @puts(i8* dereferenceable(1) %70)
%72 = tail call zeroext i16 (...) @randomunsignedshort()
%73 = tail call zeroext i16 (...) @randomunsignedshort()
%74 = zext i16 %72 to i32
%75 = zext i16 %73 to i32
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %74, i32 %75)
%77 = tail call zeroext i16 @readunsignedshort(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%78 = and i16 %73, %72
%79 = icmp eq i16 %77, %78
%80 = select i1 %79, 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)
%81 = tail call i32 @puts(i8* dereferenceable(1) %80)
ret void
}