#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 getbit();
int getbyte();
int /*<<< orphan*/ printf(char *);
synchronize() {
  int decaleur = 0, val;
  printf("Searching synchro...\n");
  while (1) {
    while ((decaleur & 0xff) != 0x68)
      decaleur = (decaleur << 1) | getbit();
    if (getbyte() != 0x16)
      continue;
    if (getbyte() != 0x16)
      continue;
    if (getbyte() != 0x16)
      continue;
    do {
      val = getbyte();
    } while (val == 0x16);
    if (val == 0x24)
      break;
  }
}


x86 assembly (clang, -O0):
<synchronize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
jmp    1150 <synchronize+0x20>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
cmp    $0x68,%eax
je     1180 <synchronize+0x50>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getbit@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <synchronize+0x20>
mov    $0x0,%al
call   1030 <getbyte@plt>
cmp    $0x16,%eax
je     1195 <synchronize+0x65>
jmp    114b <synchronize+0x1b>
mov    $0x0,%al
call   1030 <getbyte@plt>
cmp    $0x16,%eax
je     11aa <synchronize+0x7a>
jmp    114b <synchronize+0x1b>
mov    $0x0,%al
call   1030 <getbyte@plt>
cmp    $0x16,%eax
je     11bf <synchronize+0x8f>
jmp    114b <synchronize+0x1b>
jmp    11c4 <synchronize+0x94>
mov    $0x0,%al
call   1030 <getbyte@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x16,-0xc(%rbp)
je     11c4 <synchronize+0x94>
cmpl   $0x24,-0xc(%rbp)
jne    11e7 <synchronize+0xb7>
jmp    11ec <synchronize+0xbc>
jmp    114b <synchronize+0x1b>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<synchronize>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    115b <synchronize+0x2b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebx,%ebx
xor    %eax,%eax
call   1050 <getbit@plt>
or     %eax,%ebx
cmp    $0x68,%bl
jne    1150 <synchronize+0x20>
xor    %eax,%eax
call   1030 <getbyte@plt>
cmp    $0x16,%eax
jne    115b <synchronize+0x2b>
xor    %eax,%eax
call   1030 <getbyte@plt>
cmp    $0x16,%eax
jne    115b <synchronize+0x2b>
xor    %eax,%eax
call   1030 <getbyte@plt>
cmp    $0x16,%eax
jne    115b <synchronize+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getbyte@plt>
cmp    $0x16,%eax
je     1190 <synchronize+0x60>
cmp    $0x24,%eax
jne    115b <synchronize+0x2b>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Searching synchro...\0A\00"
define i32 @synchronize() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %18, %22, %26, %37
br label %6
6: ; preds = %10, %5
%7 = load i32, i32* %2
%8 = and i32 %7, 255
%9 = icmp ne i32 %8, 104
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %2
%12 = shl i32 %11, 1
%13 = call i32 (...) @getbit()
%14 = or i32 %12, %13
store i32 %14, i32* %2
br label %6
15: ; preds = %6
%16 = call i32 (...) @getbyte()
%17 = icmp ne i32 %16, 22
br i1 %17, label %18, label %19
18: ; preds = %15
br label %5
19: ; preds = %15
%20 = call i32 (...) @getbyte()
%21 = icmp ne i32 %20, 22
br i1 %21, label %22, label %23
22: ; preds = %19
br label %5
23: ; preds = %19
%24 = call i32 (...) @getbyte()
%25 = icmp ne i32 %24, 22
br i1 %25, label %26, label %27
26: ; preds = %23
br label %5
27: ; preds = %23
br label %28
28: ; preds = %30, %27
%29 = call i32 (...) @getbyte()
store i32 %29, i32* %3
br label %30
30: ; preds = %28
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 22
br i1 %32, label %28, label %33
33: ; preds = %30
%34 = load i32, i32* %3
%35 = icmp eq i32 %34, 36
br i1 %35, label %36, label %37
36: ; preds = %33
br label %38
37: ; preds = %33
br label %5
38: ; preds = %36
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@str = [21 x i8] c"Searching synchro...\00"
define i32 @synchronize() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %17, %0
%3 = phi i32 [ 0, %0 ], [ %14, %17 ]
%4 = and i32 %3, 255
%5 = icmp eq i32 %4, 104
br i1 %5, label %13, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %10, %6 ], [ %3, %2 ]
%8 = shl i32 %7, 1
%9 = tail call i32 (...) @getbit()
%10 = or i32 %9, %8
%11 = and i32 %10, 255
%12 = icmp eq i32 %11, 104
br i1 %12, label %13, label %6
13: ; preds = %6, %2
%14 = phi i32 [ %3, %2 ], [ %10, %6 ]
%15 = tail call i32 (...) @getbyte()
%16 = icmp eq i32 %15, 22
br i1 %16, label %18, label %17
17: ; preds = %24, %13, %18, %21
br label %2
18: ; preds = %13
%19 = tail call i32 (...) @getbyte()
%20 = icmp eq i32 %19, 22
br i1 %20, label %21, label %17
21: ; preds = %18
%22 = tail call i32 (...) @getbyte()
%23 = icmp eq i32 %22, 22
br i1 %23, label %24, label %17
24: ; preds = %21, %24
%25 = tail call i32 (...) @getbyte()
switch i32 %25, label %17 [
i32 22, label %24
i32 36, label %26
]
26: ; preds = %24
ret i32 undef
}