#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*/ fc8151_read(void *, int, unsigned char *);
int /*<<< orphan*/ fc8151_write(void *, int, int);
int /*<<< orphan*/ msWait(int);
int fc8151_set_filter(void *hDevice) {
  int i;
  unsigned char cal_mon = 0;
  fc8151_write(hDevice, 0x3B, 0x01);
  fc8151_write(hDevice, 0x3D, 0x31);
  fc8151_write(hDevice, 0x3B, 0x00);
  for (i = 0; i < 10; i++) {
    msWait(5);
    fc8151_read(hDevice, 0x33, &cal_mon);
    if ((cal_mon & 0xC0) == 0xC0)
      break;
    fc8151_write(hDevice, 0x32, 0x01);
    fc8151_write(hDevice, 0x32, 0x09);
  }
  fc8151_write(hDevice, 0x32, 0x01);
  return 0;
}


x86 assembly (clang, -O0):
<fc8151_set_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3b,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
mov    $0x31,%edx
call   1050 <fc8151_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3b,%esi
xor    %edx,%edx
call   1050 <fc8151_write@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11f0 <fc8151_set_filter+0xc0>
mov    $0x5,%edi
call   1040 <msWait@plt>
mov    -0x8(%rbp),%rdi
mov    $0x33,%esi
lea    -0xd(%rbp),%rdx
call   1030 <fc8151_read@plt>
movzbl -0xd(%rbp),%eax
and    $0xc0,%eax
cmp    $0xc0,%eax
jne    11bc <fc8151_set_filter+0x8c>
jmp    11f0 <fc8151_set_filter+0xc0>
mov    -0x8(%rbp),%rdi
mov    $0x32,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x32,%esi
mov    $0x9,%edx
call   1050 <fc8151_write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <fc8151_set_filter+0x4d>
mov    -0x8(%rbp),%rdi
mov    $0x32,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8151_set_filter>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
mov    $0x3b,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
mov    %rbx,%rdi
mov    $0x3d,%esi
mov    $0x31,%edx
call   1050 <fc8151_write@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
xor    %edx,%edx
call   1050 <fc8151_write@plt>
mov    $0xa,%ebp
lea    0xf(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1040 <msWait@plt>
mov    %rbx,%rdi
mov    $0x33,%esi
mov    %r14,%rdx
call   1030 <fc8151_read@plt>
cmpb   $0xbf,0xf(%rsp)
ja     11ca <fc8151_set_filter+0x9a>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    $0x9,%edx
call   1050 <fc8151_write@plt>
add    $0xffffffff,%ebp
jne    1180 <fc8151_set_filter+0x50>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    $0x1,%edx
call   1050 <fc8151_write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8151_set_filter(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %4
%5 = load i8*, i8** %2
%6 = call i32 @fc8151_write(i8* %5, i32 59, i32 1)
%7 = load i8*, i8** %2
%8 = call i32 @fc8151_write(i8* %7, i32 61, i32 49)
%9 = load i8*, i8** %2
%10 = call i32 @fc8151_write(i8* %9, i32 59, i32 0)
store i32 0, i32* %3
br label %11
11: ; preds = %28, %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = call i32 @msWait(i32 5)
%16 = load i8*, i8** %2
%17 = call i32 @fc8151_read(i8* %16, i32 51, i8* %4)
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = and i32 %19, 192
%21 = icmp eq i32 %20, 192
br i1 %21, label %22, label %23
22: ; preds = %14
br label %31
23: ; preds = %14
%24 = load i8*, i8** %2
%25 = call i32 @fc8151_write(i8* %24, i32 50, i32 1)
%26 = load i8*, i8** %2
%27 = call i32 @fc8151_write(i8* %26, i32 50, i32 9)
br label %28
28: ; preds = %23
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %11
31: ; preds = %22, %11
%32 = load i8*, i8** %2
%33 = call i32 @fc8151_write(i8* %32, i32 50, i32 1)
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8151_set_filter(i8* %0) {
%2 = alloca i8
store i8 0, i8* %2
%3 = tail call i32 @fc8151_write(i8* %0, i32 59, i32 1)
%4 = tail call i32 @fc8151_write(i8* %0, i32 61, i32 49)
%5 = tail call i32 @fc8151_write(i8* %0, i32 59, i32 0)
br label %6
6: ; preds = %1, %12
%7 = phi i32 [ 0, %1 ], [ %15, %12 ]
%8 = call i32 @msWait(i32 5)
%9 = call i32 @fc8151_read(i8* %0, i32 51, i8* %2)
%10 = load i8, i8* %2
%11 = icmp ugt i8 %10, -65
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = call i32 @fc8151_write(i8* %0, i32 50, i32 1)
%14 = call i32 @fc8151_write(i8* %0, i32 50, i32 9)
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %6
17: ; preds = %6, %12
%18 = call i32 @fc8151_write(i8* %0, i32 50, i32 1)
ret i32 0
}