#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 short VIM_JPEG_GetFrameCount();
int /*<<< orphan*/ VIM_SIF_EnableSyncGen(unsigned char);
int /*<<< orphan*/ VIM_USER_DelayMs(int);
void VIM_MAPI_EnableSyncGen(unsigned char bEnable) {
  unsigned long i = 400;
  unsigned short iCurrentFrame, iStartFram;
  iStartFram = VIM_JPEG_GetFrameCount();
  VIM_SIF_EnableSyncGen(bEnable);
  if (bEnable == 0) {
    while (i--) {
      iCurrentFrame = VIM_JPEG_GetFrameCount();
      if ((iCurrentFrame - iStartFram) > 1)
        break;
      VIM_USER_DelayMs(1);
    }
  }
}


x86 assembly (clang, -O0):
<VIM_MAPI_EnableSyncGen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movq   $0x190,-0x10(%rbp)
mov    $0x0,%al
call   1030 <VIM_JPEG_GetFrameCount@plt>
mov    %ax,-0x14(%rbp)
movzbl -0x1(%rbp),%edi
call   1040 <VIM_SIF_EnableSyncGen@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jne    11bc <VIM_MAPI_EnableSyncGen+0x8c>
jmp    116c <VIM_MAPI_EnableSyncGen+0x3c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11b7 <VIM_MAPI_EnableSyncGen+0x87>
mov    $0x0,%al
call   1030 <VIM_JPEG_GetFrameCount@plt>
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
jle    11a8 <VIM_MAPI_EnableSyncGen+0x78>
jmp    11b7 <VIM_MAPI_EnableSyncGen+0x87>
mov    $0x1,%edi
call   1050 <VIM_USER_DelayMs@plt>
jmp    116c <VIM_MAPI_EnableSyncGen+0x3c>
jmp    11bc <VIM_MAPI_EnableSyncGen+0x8c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VIM_MAPI_EnableSyncGen>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <VIM_JPEG_GetFrameCount@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <VIM_SIF_EnableSyncGen@plt>
test   %ebp,%ebp
jne    1180 <VIM_MAPI_EnableSyncGen+0x50>
movzwl %bx,%ebx
mov    $0xfffffffffffffe70,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <VIM_JPEG_GetFrameCount@plt>
movzwl %ax,%eax
sub    %ebx,%eax
cmp    $0x1,%eax
jg     1180 <VIM_MAPI_EnableSyncGen+0x50>
mov    $0x1,%edi
call   1050 <VIM_USER_DelayMs@plt>
inc    %rbp
jne    1160 <VIM_MAPI_EnableSyncGen+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @VIM_MAPI_EnableSyncGen(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i64
%4 = alloca i16
%5 = alloca i16
store i8 %0, i8* %2
store i64 400, i64* %3
%6 = call zeroext i16 (...) @VIM_JPEG_GetFrameCount()
store i16 %6, i16* %5
%7 = load i8, i8* %2
%8 = call i32 @VIM_SIF_EnableSyncGen(i8 zeroext %7)
%9 = load i8, i8* %2
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %1
br label %13
13: ; preds = %26, %12
%14 = load i64, i64* %3
%15 = add i64 %14, -1
store i64 %15, i64* %3
%16 = icmp ne i64 %14, 0
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = call zeroext i16 (...) @VIM_JPEG_GetFrameCount()
store i16 %18, i16* %4
%19 = load i16, i16* %4
%20 = zext i16 %19 to i32
%21 = load i16, i16* %5
%22 = zext i16 %21 to i32
%23 = sub nsw i32 %20, %22
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %17
br label %28
26: ; preds = %17
%27 = call i32 @VIM_USER_DelayMs(i32 1)
br label %13
28: ; preds = %25, %13
br label %29
29: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
define void @VIM_MAPI_EnableSyncGen(i8 zeroext %0) {
%2 = tail call zeroext i16 (...) @VIM_JPEG_GetFrameCount()
%3 = tail call i32 @VIM_SIF_EnableSyncGen(i8 zeroext %0)
%4 = icmp eq i8 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = zext i16 %2 to i32
br label %7
7: ; preds = %5, %13
%8 = phi i64 [ 399, %5 ], [ %15, %13 ]
%9 = tail call zeroext i16 (...) @VIM_JPEG_GetFrameCount()
%10 = zext i16 %9 to i32
%11 = sub nsw i32 %10, %6
%12 = icmp sgt i32 %11, 1
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @VIM_USER_DelayMs(i32 1)
%15 = add nsw i64 %8, -1
%16 = icmp eq i64 %8, 0
br i1 %16, label %17, label %7
17: ; preds = %13, %7, %1
ret void
}