#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 */
typedef int uint8_t;

/* Variables and functions */
int PinGetPIN_D();
int /*<<< orphan*/ PinSetPIN_A(int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char **argv) {
  uint8_t expected[8] = {1, 0, 1, 1, 1, 0, 1, 1};
  int a;
  PinSetPIN_A(0);
  PinSetPIN_A(0);
  for (a = 0; a < 4; a++) {
    PinSetPIN_A(1);
    if ((PinGetPIN_D() & 1) != expected[a * 2 + 0]) {
      printf("Expected %d, but got %d, 0->1 transition", expected[a * 2 + 0],
             (PinGetPIN_D() & 1));
      return 1;
    }
    PinSetPIN_A(0);
    if ((PinGetPIN_D() & 1) != expected[a * 2 + 1]) {
      printf("Expected %d, but got %d, 1->0 transition", expected[a * 2 + 1],
             (PinGetPIN_D() & 1));
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    1267 <main+0x137>
mov    $0x1,%edi
call   1050 <PinSetPIN_A@plt>
mov    $0x0,%al
call   1040 <PinGetPIN_D@plt>
and    $0x1,%eax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     11f4 <main+0xc4>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
add    $0x0,%eax
cltq
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <PinGetPIN_D@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
and    $0x1,%edx
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <main+0x13e>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
mov    $0x0,%al
call   1040 <PinGetPIN_D@plt>
and    $0x1,%eax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     1254 <main+0x124>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <PinGetPIN_D@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
and    $0x1,%edx
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <main+0x13e>
jmp    1259 <main+0x129>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1187 <main+0x57>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
je     11e6 <main+0xb6>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
jne    121c <main+0xec>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
je     11e6 <main+0xb6>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
je     121c <main+0xec>
mov    $0x1,%edi
call   1050 <PinSetPIN_A@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
je     11e6 <main+0xb6>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
jne    121c <main+0xec>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
test   $0x1,%al
jne    1205 <main+0xd5>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
and    $0x1,%eax
lea    0xe09(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
jmp    123b <main+0x10b>
xor    %edi,%edi
call   1050 <PinSetPIN_A@plt>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
mov    $0x0,%ebp
test   $0x1,%al
jne    123b <main+0x10b>
xor    %eax,%eax
call   1040 <PinGetPIN_D@plt>
and    $0x1,%eax
lea    0xdfc(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.expected = [8 x i32] [i32 1, i32 0, i32 1, i32 1, i32 1, i32 0, i32 1, i32 1]
@.str = [41 x i8] c"Expected %d, but got %d, 0->1 transition\00"
@.str.1 = [41 x i8] c"Expected %d, but got %d, 1->0 transition\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [8 x i32]* %6 to i8*
%9 = call i32 @PinSetPIN_A(i32 0)
%10 = call i32 @PinSetPIN_A(i32 0)
store i32 0, i32* %7
br label %11
11: ; preds = %57, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %60
14: ; preds = %11
%15 = call i32 @PinSetPIN_A(i32 1)
%16 = call i32 (...) @PinGetPIN_D()
%17 = and i32 %16, 1
%18 = load i32, i32* %7
%19 = mul nsw i32 %18, 2
%20 = add nsw i32 %19, 0
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = icmp ne i32 %17, %23
br i1 %24, label %25, label %35
25: ; preds = %14
%26 = load i32, i32* %7
%27 = mul nsw i32 %26, 2
%28 = add nsw i32 %27, 0
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (...) @PinGetPIN_D()
%33 = and i32 %32, 1
%34 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %33)
store i32 1, i32* %3
br label %61
35: ; preds = %14
%36 = call i32 @PinSetPIN_A(i32 0)
%37 = call i32 (...) @PinGetPIN_D()
%38 = and i32 %37, 1
%39 = load i32, i32* %7
%40 = mul nsw i32 %39, 2
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp ne i32 %38, %44
br i1 %45, label %46, label %56
46: ; preds = %35
%47 = load i32, i32* %7
%48 = mul nsw i32 %47, 2
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (...) @PinGetPIN_D()
%54 = and i32 %53, 1
%55 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %54)
store i32 1, i32* %3
br label %61
56: ; preds = %35
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %11
60: ; preds = %11
store i32 0, i32* %3
br label %61
61: ; preds = %60, %46, %25
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [41 x i8] c"Expected %d, but got %d, 0->1 transition\00"
@.str.1 = [41 x i8] c"Expected %d, but got %d, 1->0 transition\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @PinSetPIN_A(i32 0)
%4 = tail call i32 @PinSetPIN_A(i32 0)
%5 = tail call i32 @PinSetPIN_A(i32 1)
%6 = tail call i32 (...) @PinGetPIN_D()
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %39, label %43
9: ; preds = %43
%10 = tail call i32 @PinSetPIN_A(i32 1)
%11 = tail call i32 (...) @PinGetPIN_D()
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %9
%15 = tail call i32 @PinSetPIN_A(i32 0)
%16 = tail call i32 (...) @PinGetPIN_D()
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
br i1 %18, label %48, label %19
19: ; preds = %14
%20 = tail call i32 @PinSetPIN_A(i32 1)
%21 = tail call i32 (...) @PinGetPIN_D()
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
br i1 %23, label %39, label %24
24: ; preds = %19
%25 = tail call i32 @PinSetPIN_A(i32 0)
%26 = tail call i32 (...) @PinGetPIN_D()
%27 = and i32 %26, 1
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %24
%30 = tail call i32 @PinSetPIN_A(i32 1)
%31 = tail call i32 (...) @PinGetPIN_D()
%32 = and i32 %31, 1
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = tail call i32 @PinSetPIN_A(i32 0)
%36 = tail call i32 (...) @PinGetPIN_D()
%37 = and i32 %36, 1
%38 = icmp eq i32 %37, 0
br i1 %38, label %48, label %53
39: ; preds = %29, %19, %9, %2
%40 = tail call i32 (...) @PinGetPIN_D()
%41 = and i32 %40, 1
%42 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 1, i32 %41)
br label %53
43: ; preds = %2
%44 = tail call i32 @PinSetPIN_A(i32 0)
%45 = tail call i32 (...) @PinGetPIN_D()
%46 = and i32 %45, 1
%47 = icmp eq i32 %46, 0
br i1 %47, label %9, label %48
48: ; preds = %34, %24, %14, %43
%49 = phi i32 [ 0, %43 ], [ 1, %14 ], [ 0, %24 ], [ 1, %34 ]
%50 = tail call i32 (...) @PinGetPIN_D()
%51 = and i32 %50, 1
%52 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %51)
br label %53
53: ; preds = %34, %48, %39
%54 = phi i32 [ 1, %39 ], [ 1, %48 ], [ 0, %34 ]
ret i32 %54
}