#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 */
unsigned char get();
char wait_trans(int N) {
  unsigned char t, t1, i;
  t = get();
  for (i = 0; i < N; i++) {
    t1 = t;
    t = get();
    if (t1 ^ t) {
      return t;
    }
  }
  return 2;
}


x86 assembly (clang, -O0):
<wait_trans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <get@plt>
mov    %al,-0x9(%rbp)
movb   $0x0,-0xb(%rbp)
movzbl -0xb(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1176 <wait_trans+0x66>
mov    -0x9(%rbp),%al
mov    %al,-0xa(%rbp)
mov    $0x0,%al
call   1030 <get@plt>
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0x9(%rbp),%ecx
xor    %ecx,%eax
cmp    $0x0,%eax
je     1164 <wait_trans+0x54>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    117a <wait_trans+0x6a>
jmp    1169 <wait_trans+0x59>
mov    -0xb(%rbp),%al
add    $0x1,%al
mov    %al,-0xb(%rbp)
jmp    1129 <wait_trans+0x19>
movb   $0x2,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_trans>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %eax,%eax
call   1030 <get@plt>
mov    $0x2,%r14b
test   %r15d,%r15d
jle    114c <wait_trans+0x3c>
mov    %eax,%ebx
mov    $0x1,%bpl
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <get@plt>
cmp    %al,%bl
jne    1149 <wait_trans+0x39>
movzbl %bpl,%eax
lea    0x1(%rax),%ebp
cmp    %r15d,%eax
jl     1130 <wait_trans+0x20>
jmp    114c <wait_trans+0x3c>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @wait_trans(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i32 %0, i32* %3
%7 = call zeroext i8 (...) @get()
store i8 %7, i8* %4
store i8 0, i8* %6
br label %8
8: ; preds = %25, %1
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = load i8, i8* %4
store i8 %14, i8* %5
%15 = call zeroext i8 (...) @get()
store i8 %15, i8* %4
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = xor i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = load i8, i8* %4
store i8 %23, i8* %2
br label %29
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i8, i8* %6
%27 = add i8 %26, 1
store i8 %27, i8* %6
br label %8
28: ; preds = %8
store i8 2, i8* %2
br label %29
29: ; preds = %28, %22
%30 = load i8, i8* %2
ret i8 %30
}

LLVM IR (-O2):
define signext i8 @wait_trans(i32 %0) {
%2 = tail call zeroext i8 (...) @get()
%3 = icmp sgt i32 %0, 0
br i1 %3, label %7, label %12
4: ; preds = %7
%5 = zext i8 %11 to i32
%6 = icmp slt i32 %5, %0
br i1 %6, label %7, label %12
7: ; preds = %1, %4
%8 = phi i8 [ %11, %4 ], [ 0, %1 ]
%9 = tail call zeroext i8 (...) @get()
%10 = icmp eq i8 %2, %9
%11 = add i8 %8, 1
br i1 %10, label %4, label %12
12: ; preds = %7, %4, %1
%13 = phi i8 [ 2, %1 ], [ 2, %4 ], [ %9, %7 ]
ret i8 %13
}