#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*/ bbm_read(void *, int, unsigned char *);
int /*<<< orphan*/ bbm_word_read(void *, int, unsigned short *);
int /*<<< orphan*/ bbm_write(void *, int, int);
scalar_t__ fc8080_channel_deselect(void *, unsigned char, unsigned char);
int fc8080_video_deselect(void *handle, unsigned char subch_id,
                          unsigned char buf_id, unsigned char cdi_id) {
  unsigned short fec_en = 0;
  unsigned char buf_en = 0;
  bbm_write(handle, 0x0910 + buf_id, 0x00);
  bbm_word_read(handle, 0x0e0a, &fec_en);
  if (!((fec_en & 0xff00) && (fec_en & 0x00ff) && cdi_id == 0))
    bbm_write(handle, 0x0e0a + cdi_id, 0x00);
  if (fc8080_channel_deselect(handle, subch_id, buf_id) != 0)
    return 1;
  bbm_read(handle, 0x0910, &buf_en);
  if (buf_en == 0 && (fec_en & 0xff00) && cdi_id == 1)
    bbm_write(handle, 0x0e0a, 0x00);
  return 0;
}


x86 assembly (clang, -O0):
<fc8080_video_deselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %cl,-0x12(%rbp)
mov    %al,-0x13(%rbp)
movw   $0x0,-0x16(%rbp)
movb   $0x0,-0x17(%rbp)
mov    -0x10(%rbp),%rdi
movzbl -0x12(%rbp),%esi
add    $0x910,%esi
xor    %edx,%edx
call   1030 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    $0xe0a,%esi
lea    -0x16(%rbp),%rdx
call   1060 <bbm_word_read@plt>
movzwl -0x16(%rbp),%eax
and    $0xff00,%eax
cmp    $0x0,%eax
je     11be <fc8080_video_deselect+0x7e>
movzwl -0x16(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     11be <fc8080_video_deselect+0x7e>
movzbl -0x13(%rbp),%eax
cmp    $0x0,%eax
je     11d3 <fc8080_video_deselect+0x93>
mov    -0x10(%rbp),%rdi
movzbl -0x13(%rbp),%esi
add    $0xe0a,%esi
xor    %edx,%edx
call   1030 <bbm_write@plt>
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
movzbl %al,%esi
movzbl -0x12(%rbp),%edx
call   1050 <fc8080_channel_deselect@plt>
cmp    $0x0,%rax
je     11fc <fc8080_video_deselect+0xbc>
movl   $0x1,-0x4(%rbp)
jmp    1251 <fc8080_video_deselect+0x111>
mov    -0x10(%rbp),%rdi
mov    $0x910,%esi
lea    -0x17(%rbp),%rdx
call   1040 <bbm_read@plt>
movzbl -0x17(%rbp),%eax
cmp    $0x0,%eax
jne    124a <fc8080_video_deselect+0x10a>
movzwl -0x16(%rbp),%eax
and    $0xff00,%eax
cmp    $0x0,%eax
je     124a <fc8080_video_deselect+0x10a>
movzbl -0x13(%rbp),%eax
cmp    $0x1,%eax
jne    124a <fc8080_video_deselect+0x10a>
mov    -0x10(%rbp),%rdi
mov    $0xe0a,%esi
xor    %edx,%edx
call   1030 <bbm_write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8080_video_deselect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
movw   $0x0,0x6(%rsp)
movb   $0x0,0x5(%rsp)
lea    0x910(%rbp),%esi
xor    %edx,%edx
call   1030 <bbm_write@plt>
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
mov    $0xe0a,%esi
call   1060 <bbm_word_read@plt>
movzwl 0x6(%rsp),%eax
test   $0xff00,%eax
je     1195 <fc8080_video_deselect+0x55>
test   %r14b,%r14b
jne    1195 <fc8080_video_deselect+0x55>
movzbl %al,%eax
test   %eax,%eax
jne    11a9 <fc8080_video_deselect+0x69>
movzbl %r14b,%esi
add    $0xe0a,%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <bbm_write@plt>
movzbl %r15b,%esi
movzbl %bpl,%edx
mov    %rbx,%rdi
call   1050 <fc8080_channel_deselect@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1201 <fc8080_video_deselect+0xc1>
lea    0x5(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x910,%esi
call   1040 <bbm_read@plt>
xor    %ebp,%ebp
cmpb   $0x0,0x5(%rsp)
jne    1201 <fc8080_video_deselect+0xc1>
cmp    $0x1,%r14b
jne    1201 <fc8080_video_deselect+0xc1>
movzwl 0x6(%rsp),%eax
cmp    $0x100,%eax
jb     1201 <fc8080_video_deselect+0xc1>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0xe0a,%esi
xor    %edx,%edx
call   1030 <bbm_write@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8080_video_deselect(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i16
%11 = alloca i8
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
store i16 0, i16* %10
store i8 0, i8* %11
%12 = load i8*, i8** %6
%13 = load i8, i8* %8
%14 = zext i8 %13 to i32
%15 = add nsw i32 2320, %14
%16 = call i32 @bbm_write(i8* %12, i32 %15, i32 0)
%17 = load i8*, i8** %6
%18 = call i32 @bbm_word_read(i8* %17, i32 3594, i16* %10)
%19 = load i16, i16* %10
%20 = zext i16 %19 to i32
%21 = and i32 %20, 65280
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %4
%24 = load i16, i16* %10
%25 = zext i16 %24 to i32
%26 = and i32 %25, 255
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8, i8* %9
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %28, %23, %4
%33 = load i8*, i8** %6
%34 = load i8, i8* %9
%35 = zext i8 %34 to i32
%36 = add nsw i32 3594, %35
%37 = call i32 @bbm_write(i8* %33, i32 %36, i32 0)
br label %38
38: ; preds = %32, %28
%39 = load i8*, i8** %6
%40 = load i8, i8* %7
%41 = load i8, i8* %8
%42 = call i64 @fc8080_channel_deselect(i8* %39, i8 zeroext %40, i8 zeroext %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %5
br label %64
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = call i32 @bbm_read(i8* %46, i32 2320, i8* %11)
%48 = load i8, i8* %11
%49 = zext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %45
%52 = load i16, i16* %10
%53 = zext i16 %52 to i32
%54 = and i32 %53, 65280
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %51
%57 = load i8, i8* %9
%58 = zext i8 %57 to i32
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i8*, i8** %6
%62 = call i32 @bbm_write(i8* %61, i32 3594, i32 0)
br label %63
63: ; preds = %60, %56, %51, %45
store i32 0, i32* %5
br label %64
64: ; preds = %63, %44
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
define i32 @fc8080_video_deselect(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i16
%6 = alloca i8
%7 = bitcast i16* %5 to i8*
store i16 0, i16* %5
store i8 0, i8* %6
%8 = zext i8 %2 to i32
%9 = add nuw nsw i32 %8, 2320
%10 = tail call i32 @bbm_write(i8* %0, i32 %9, i32 0)
%11 = call i32 @bbm_word_read(i8* %0, i32 3594, i16* %5)
%12 = load i16, i16* %5
%13 = zext i16 %12 to i32
%14 = and i32 %13, 65280
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %4
%17 = and i32 %13, 255
%18 = icmp ne i32 %17, 0
%19 = icmp eq i8 %3, 0
%20 = and i1 %19, %18
br i1 %20, label %25, label %21
21: ; preds = %16, %4
%22 = zext i8 %3 to i32
%23 = add nuw nsw i32 %22, 3594
%24 = call i32 @bbm_write(i8* %0, i32 %23, i32 0)
br label %25
25: ; preds = %16, %21
%26 = call i64 @fc8080_channel_deselect(i8* %0, i8 zeroext %1, i8 zeroext %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = call i32 @bbm_read(i8* %0, i32 2320, i8* %6)
%30 = load i8, i8* %6
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i16, i16* %5
%34 = icmp ugt i16 %33, 255
%35 = icmp eq i8 %3, 1
%36 = and i1 %35, %34
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @bbm_write(i8* %0, i32 3594, i32 0)
br label %39
39: ; preds = %28, %32, %37, %25
%40 = phi i32 [ 1, %25 ], [ 0, %37 ], [ 0, %32 ], [ 0, %28 ]
ret i32 %40
}