#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*/ saa7114_write_reg(unsigned char, unsigned char);
int saa7114_set_decoder_vbi_format(int start, int end, int format) {
  int i;
  unsigned char data;
  for (i = start; i <= end; i++) {
    switch (format) {
    case 0x1:
      data = 0xFF;
      break;
    case 0x2:
      data = 0x77;
      break;
    case 0x4:
      data = 0x55;
      break;
    case 0x8:
      data = 0xCC;
      break;
    default:
      return (-2);
    }
    saa7114_write_reg((unsigned char)(0x3F + i), data);
  }
  return 0;
}


x86 assembly (clang, -O0):
<saa7114_set_decoder_vbi_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11ac <saa7114_set_decoder_vbi_format+0x9c>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x7,%eax
ja     1180 <saa7114_set_decoder_vbi_format+0x70>
mov    -0x20(%rbp),%rax
lea    0xead(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0xff,-0x15(%rbp)
jmp    118c <saa7114_set_decoder_vbi_format+0x7c>
movb   $0x77,-0x15(%rbp)
jmp    118c <saa7114_set_decoder_vbi_format+0x7c>
movb   $0x55,-0x15(%rbp)
jmp    118c <saa7114_set_decoder_vbi_format+0x7c>
movb   $0xcc,-0x15(%rbp)
jmp    118c <saa7114_set_decoder_vbi_format+0x7c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b3 <saa7114_set_decoder_vbi_format+0xa3>
mov    -0x14(%rbp),%eax
add    $0x3f,%eax
movzbl %al,%edi
movzbl -0x15(%rbp),%esi
call   1030 <saa7114_write_reg@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <saa7114_set_decoder_vbi_format+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saa7114_set_decoder_vbi_format>:
cmp    %esi,%edi
jle    1117 <saa7114_set_decoder_vbi_format+0x7>
xor    %eax,%eax
ret
mov    $0xfffffffe,%eax
cmp    $0x8,%edx
ja     117b <saa7114_set_decoder_vbi_format+0x6b>
mov    $0x116,%ecx
bt     %edx,%ecx
jae    117b <saa7114_set_decoder_vbi_format+0x6b>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
cmp    %edi,%esi
cmovle %edi,%r14d
lea    -0x8(,%rdx,8),%ecx
mov    $0x55cc77ff,%eax
shr    %cl,%eax
mov    %edx,%ecx
add    $0xffffffff,%ecx
cmp    $0x4,%ecx
mov    $0xcc,%ecx
cmovb  %eax,%ecx
add    $0x1,%r14d
movzbl %cl,%ebp
nop
lea    0x3f(%rbx),%eax
movzbl %al,%edi
mov    %ebp,%esi
call   1030 <saa7114_write_reg@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1160 <saa7114_set_decoder_vbi_format+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @saa7114_set_decoder_vbi_format(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
store i32 %10, i32* %8
br label %11
11: ; preds = %28, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32, i32* %7
switch i32 %16, label %21 [
i32 1, label %17
i32 2, label %18
i32 4, label %19
i32 8, label %20
]
17: ; preds = %15
store i8 -1, i8* %9
br label %22
18: ; preds = %15
store i8 119, i8* %9
br label %22
19: ; preds = %15
store i8 85, i8* %9
br label %22
20: ; preds = %15
store i8 -52, i8* %9
br label %22
21: ; preds = %15
store i32 -2, i32* %4
br label %32
22: ; preds = %20, %19, %18, %17
%23 = load i32, i32* %8
%24 = add nsw i32 63, %23
%25 = trunc i32 %24 to i8
%26 = load i8, i8* %9
%27 = call i32 @saa7114_write_reg(i8 zeroext %25, i8 zeroext %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %11
31: ; preds = %11
store i32 0, i32* %4
br label %32
32: ; preds = %31, %21
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @saa7114_set_decoder_vbi_format(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %0, %1
br i1 %4, label %21, label %5
5: ; preds = %3
switch i32 %2, label %21 [
i32 1, label %6
i32 2, label %6
i32 4, label %6
i32 8, label %6
]
6: ; preds = %5, %5, %5, %5
%7 = call i32 @llvm.smax.i32(i32 %1, i32 %0)
%8 = add i32 %2, -1
%9 = icmp ult i32 %8, 4
%10 = shl i32 %8, 3
%11 = lshr i32 1439463423, %10
%12 = trunc i32 %11 to i8
%13 = select i1 %9, i8 %12, i8 -52
br label %14
14: ; preds = %6, %14
%15 = phi i32 [ %0, %6 ], [ %19, %14 ]
%16 = trunc i32 %15 to i8
%17 = add i8 %16, 63
%18 = tail call i32 @saa7114_write_reg(i8 zeroext %17, i8 zeroext %13)
%19 = add i32 %15, 1
%20 = icmp eq i32 %15, %7
br i1 %20, label %21, label %14
21: ; preds = %14, %5, %3
%22 = phi i32 [ 0, %3 ], [ -2, %5 ], [ 0, %14 ]
ret i32 %22
}