#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*/ SCLKHigh();
int /*<<< orphan*/ SCLKLow();
scalar_t__ fSDATACheck();
signed char fDetectHiLoTransition(void) {
  unsigned long int iTimer = 0;
  iTimer = 2000000;
  while (1) {
    SCLKLow();
    if (fSDATACheck())
      break;
    SCLKHigh();
    if (iTimer-- == 0) {
      return (-1);
    }
  }
  iTimer = 2000000;
  while (1) {
    SCLKLow();
    if (!fSDATACheck()) {
      break;
    }
    SCLKHigh();
    if (iTimer-- == 0) {
      return (-1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<fDetectHiLoTransition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x1e8480,-0x10(%rbp)
mov    $0x0,%al
call   1040 <SCLKLow@plt>
mov    $0x0,%al
call   1050 <fSDATACheck@plt>
cmp    $0x0,%rax
je     1165 <fDetectHiLoTransition+0x35>
jmp    1193 <fDetectHiLoTransition+0x63>
mov    $0x0,%al
call   1030 <SCLKHigh@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jne    118e <fDetectHiLoTransition+0x5e>
movb   $0xff,-0x1(%rbp)
jmp    11ea <fDetectHiLoTransition+0xba>
jmp    1148 <fDetectHiLoTransition+0x18>
movq   $0x1e8480,-0x10(%rbp)
mov    $0x0,%al
call   1040 <SCLKLow@plt>
mov    $0x0,%al
call   1050 <fSDATACheck@plt>
cmp    $0x0,%rax
jne    11b8 <fDetectHiLoTransition+0x88>
jmp    11e6 <fDetectHiLoTransition+0xb6>
mov    $0x0,%al
call   1030 <SCLKHigh@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e1 <fDetectHiLoTransition+0xb1>
movb   $0xff,-0x1(%rbp)
jmp    11ea <fDetectHiLoTransition+0xba>
jmp    119b <fDetectHiLoTransition+0x6b>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fDetectHiLoTransition>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffffffe17b7f,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <SCLKLow@plt>
xor    %eax,%eax
call   1050 <fSDATACheck@plt>
test   %rax,%rax
jne    1161 <fDetectHiLoTransition+0x31>
xor    %eax,%eax
call   1030 <SCLKHigh@plt>
inc    %rbx
jne    1140 <fDetectHiLoTransition+0x10>
jmp    118f <fDetectHiLoTransition+0x5f>
mov    $0xffffffffffe17b7f,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <SCLKLow@plt>
xor    %eax,%eax
call   1050 <fSDATACheck@plt>
test   %rax,%rax
je     1192 <fDetectHiLoTransition+0x62>
xor    %eax,%eax
call   1030 <SCLKHigh@plt>
inc    %rbx
jne    1170 <fDetectHiLoTransition+0x40>
mov    $0xff,%bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define signext i8 @fDetectHiLoTransition() {
br label %1
1: ; preds = %6, %0
%2 = phi i64 [ 2000000, %0 ], [ %8, %6 ]
%3 = tail call i32 (...) @SCLKLow()
%4 = tail call i64 (...) @fSDATACheck()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 (...) @SCLKHigh()
%8 = add nsw i64 %2, -1
%9 = icmp eq i64 %2, 0
br i1 %9, label %19, label %1
10: ; preds = %1, %15
%11 = phi i64 [ %17, %15 ], [ 2000000, %1 ]
%12 = tail call i32 (...) @SCLKLow()
%13 = tail call i64 (...) @fSDATACheck()
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = tail call i32 (...) @SCLKHigh()
%17 = add nsw i64 %11, -1
%18 = icmp eq i64 %11, 0
br i1 %18, label %19, label %10
19: ; preds = %6, %10, %15
%20 = phi i8 [ 0, %10 ], [ -1, %15 ], [ -1, %6 ]
ret i8 %20
}