#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();
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ put_char(char);
void init_8051(void) {
  unsigned char c, d, e, f;
  c = d = e = f = 0;
  put_char('i');
  while (((c = get_char()) != 0xff) || (d != 0x00) || (e != 0xff) ||
         (f != 0x00)) {
    printf("Got %02x\n", c);
    f = e;
    e = d;
    d = c;
  }
}


x86 assembly (clang, -O0):
<init_8051>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x4(%rbp)
movb   $0x0,-0x3(%rbp)
movb   $0x0,-0x2(%rbp)
movb   $0x0,-0x1(%rbp)
mov    $0x69,%edi
call   1040 <put_char@plt>
mov    $0x0,%al
call   1050 <get_char@plt>
mov    %al,-0x1(%rbp)
movzbl %al,%ecx
mov    $0x1,%al
cmp    $0xff,%ecx
mov    %al,-0x5(%rbp)
jne    11a4 <init_8051+0x74>
movzbl -0x2(%rbp),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x5(%rbp)
jne    11a4 <init_8051+0x74>
movzbl -0x3(%rbp),%ecx
mov    $0x1,%al
cmp    $0xff,%ecx
mov    %al,-0x5(%rbp)
jne    11a4 <init_8051+0x74>
movzbl -0x4(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    11b4 <init_8051+0x84>
jmp    11db <init_8051+0xab>
lea    0xe45(%rip),%rdi
movzbl -0x1(%rbp),%esi
call   1030 <printf@plt>
mov    -0x3(%rbp),%al
mov    %al,-0x4(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x3(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x2(%rbp)
jmp    1152 <init_8051+0x22>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_8051>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x69,%edi
call   1040 <put_char@plt>
xor    %eax,%eax
call   1050 <get_char@plt>
lea    0xeb0(%rip),%r14
xor    %r12d,%r12d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%ebx
mov    %eax,%r15d
movzbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <get_char@plt>
mov    %eax,%ecx
and    %bl,%cl
or     %r12b,%bpl
mov    %ebx,%r12d
jne    1160 <init_8051+0x30>
mov    %ebx,%r12d
cmp    $0xff,%cl
jne    1160 <init_8051+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Got %02x\0A\00"
define void @init_8051() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 0, i8* %4
store i8 0, i8* %3
store i8 0, i8* %2
store i8 0, i8* %1
%5 = call i32 @put_char(i8 signext 105)
br label %6
6: ; preds = %24, %0
%7 = call zeroext i8 (...) @get_char()
store i8 %7, i8* %1
%8 = zext i8 %7 to i32
%9 = icmp ne i32 %8, 255
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = icmp ne i32 %16, 255
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %18, %14, %10, %6
%23 = phi i1 [ true, %14 ], [ true, %10 ], [ true, %6 ], [ %21, %18 ]
br i1 %23, label %24, label %30
24: ; preds = %22
%25 = load i8, i8* %1
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
%27 = load i8, i8* %3
store i8 %27, i8* %4
%28 = load i8, i8* %2
store i8 %28, i8* %3
%29 = load i8, i8* %1
store i8 %29, i8* %2
br label %6
30: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Got %02x\0A\00"
define void @init_8051() {
%1 = tail call i32 @put_char(i8 signext 105)
%2 = tail call zeroext i8 (...) @get_char()
br label %3
3: ; preds = %0, %3
%4 = phi i8 [ %2, %0 ], [ %8, %3 ]
%5 = phi i8 [ 0, %0 ], [ %6, %3 ]
%6 = phi i8 [ 0, %0 ], [ %4, %3 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 zeroext %4)
%8 = tail call zeroext i8 (...) @get_char()
%9 = and i8 %8, %6
%10 = icmp ne i8 %9, -1
%11 = or i8 %4, %5
%12 = icmp ne i8 %11, 0
%13 = or i1 %12, %10
br i1 %13, label %3, label %14
14: ; preds = %3
ret void
}