#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 */
scalar_t__ cmos_clock_busy();
int synchronize_to_clock_tick_cmos(void) {
  int i;
  for (i = 0; !cmos_clock_busy(); i++)
    if (i >= 10000000)
      return 1;
  for (i = 0; cmos_clock_busy(); i++)
    if (i >= 1000000)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<synchronize_to_clock_tick_cmos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <cmos_clock_busy@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    113c <synchronize_to_clock_tick_cmos+0x2c>
jmp    1168 <synchronize_to_clock_tick_cmos+0x58>
cmpl   $0x989680,-0x8(%rbp)
jl     1155 <synchronize_to_clock_tick_cmos+0x45>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <synchronize_to_clock_tick_cmos+0xa3>
jmp    115a <synchronize_to_clock_tick_cmos+0x4a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111f <synchronize_to_clock_tick_cmos+0xf>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <cmos_clock_busy@plt>
cmp    $0x0,%rax
je     11ac <synchronize_to_clock_tick_cmos+0x9c>
cmpl   $0xf4240,-0x8(%rbp)
jl     1199 <synchronize_to_clock_tick_cmos+0x89>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <synchronize_to_clock_tick_cmos+0xa3>
jmp    119e <synchronize_to_clock_tick_cmos+0x8e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116f <synchronize_to_clock_tick_cmos+0x5f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<synchronize_to_clock_tick_cmos>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <cmos_clock_busy@plt>
test   %rax,%rax
jne    1141 <synchronize_to_clock_tick_cmos+0x31>
mov    $0x989681,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     1173 <synchronize_to_clock_tick_cmos+0x63>
xor    %eax,%eax
call   1030 <cmos_clock_busy@plt>
test   %rax,%rax
je     1130 <synchronize_to_clock_tick_cmos+0x20>
xor    %eax,%eax
call   1030 <cmos_clock_busy@plt>
test   %rax,%rax
je     1178 <synchronize_to_clock_tick_cmos+0x68>
mov    $0xf4241,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebp
je     1173 <synchronize_to_clock_tick_cmos+0x63>
xor    %eax,%eax
call   1030 <cmos_clock_busy@plt>
test   %rax,%rax
jne    1160 <synchronize_to_clock_tick_cmos+0x50>
jmp    1178 <synchronize_to_clock_tick_cmos+0x68>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @synchronize_to_clock_tick_cmos() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %12, %0
%4 = call i64 (...) @cmos_clock_busy()
%5 = icmp ne i64 %4, 0
%6 = xor i1 %5, true
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = load i32, i32* %2
%9 = icmp sge i32 %8, 10000000
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 1, i32* %1
br label %28
11: ; preds = %7
br label %12
12: ; preds = %11
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %3
15: ; preds = %3
store i32 0, i32* %2
br label %16
16: ; preds = %24, %15
%17 = call i64 (...) @cmos_clock_busy()
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %2
%21 = icmp sge i32 %20, 1000000
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 1, i32* %1
br label %28
23: ; preds = %19
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %16
27: ; preds = %16
store i32 0, i32* %1
br label %28
28: ; preds = %27, %22, %10
%29 = load i32, i32* %1
ret i32 %29
}

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