#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 */
struct tl880_dev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ tl880_enable_aux(struct tl880_dev *);
int /*<<< orphan*/ tl880_enable_bvdo(struct tl880_dev *);
scalar_t__ tl880_read_regbits(struct tl880_dev *, int, int, int);
int /*<<< orphan*/ tl880_write_regbits(struct tl880_dev *, int,
                                       int /*<<< orphan*/, int /*<<< orphan*/,
                                       int);
void tl880_dpc_video_sync_dvd(struct tl880_dev *tl880dev) {
  static unsigned long val = 1;
  static unsigned long field_select = 0;
  static unsigned long delay_cnt = 0;
  static unsigned long dpc_hsync_cnt = 0;
  unsigned long var_10 = 0;
  dpc_hsync_cnt++;
  if (0) {
    goto loc_294ea;
  loc_294ea:
    field_select ^= 1;
    tl880_write_regbits(tl880dev, 0x10000, 0, 0, field_select);
    if (field_select == 0) {
      var_10 = 0;
      goto loc_295c9;
    }
    var_10 = 1;
    goto loc_29511;
  }
  val ^= 1;
  if (tl880_read_regbits(tl880dev, 0x10004, 2, 2)) {
    if (val == 3 || val == 1) {
      tl880_write_regbits(tl880dev, 0x10000, 0, 0, 1);
    } else {
      tl880_write_regbits(tl880dev, 0x10000, 0, 0, 0);
    }
    var_10 = 1;
    goto loc_29511;
  }
  if (val == 3 || val == 1) {
    tl880_write_regbits(tl880dev, 0x10000, 0, 0, 0);
  } else {
    tl880_write_regbits(tl880dev, 0x10000, 0, 0, 1);
  }
  var_10 = 0;
  goto loc_295c9;
loc_29511:
  if (0) {
    if (0) {
      if (0) {
      }
    } else {
      if (0) {
      }
    }
    if (0) {
    } else {
    }
    delay_cnt = 0;
    return;
  }
  if (delay_cnt <= 0) {
    if (0) {
      tl880_enable_bvdo(tl880dev);
    }
    if (0) {
      tl880_enable_aux(tl880dev);
    }
  } else {
    delay_cnt--;
  }
loc_295c9:
  if (0) {
    return;
  }
  if (0) {
    return;
  }
  if (1) {
    if (0) {
      return;
    }
    if (0) {
    }
  } else {
    if (0) {
      if (0) {
        return;
      }
    } else {
      if (0) {
        return;
      }
    }
  }
  var_10 = 0;
}


x86 assembly (clang, -O0):
<tl880_dpc_video_sync_dvd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2f15(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2f0a(%rip)
xor    %eax,%eax
test   $0x1,%al
jne    1155 <tl880_dpc_video_sync_dvd+0x35>
jmp    11b0 <tl880_dpc_video_sync_dvd+0x90>
jmp    115a <tl880_dpc_video_sync_dvd+0x3a>
mov    0x2edf(%rip),%rax
xor    $0x1,%rax
mov    %rax,0x2ed4(%rip)
mov    -0x8(%rbp),%rdi
mov    0x2ec9(%rip),%rax
mov    %eax,%r8d
mov    $0x10000,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <tl880_write_regbits@plt>
cmpq   $0x0,0x2eb0(%rip)
jne    11a3 <tl880_dpc_video_sync_dvd+0x83>
movq   $0x0,-0x10(%rbp)
jmp    12c5 <tl880_dpc_video_sync_dvd+0x1a5>
movq   $0x1,-0x10(%rbp)
jmp    129b <tl880_dpc_video_sync_dvd+0x17b>
mov    0x2e79(%rip),%rax
xor    $0x1,%rax
mov    %rax,0x2e6e(%rip)
mov    -0x8(%rbp),%rdi
mov    $0x10004,%esi
mov    $0x2,%ecx
mov    %ecx,%edx
call   1040 <tl880_read_regbits@plt>
cmp    $0x0,%rax
je     123e <tl880_dpc_video_sync_dvd+0x11e>
cmpq   $0x3,0x2e47(%rip)
03
je     11fd <tl880_dpc_video_sync_dvd+0xdd>
cmpq   $0x1,0x2e39(%rip)
01
jne    121a <tl880_dpc_video_sync_dvd+0xfa>
mov    -0x8(%rbp),%rdi
mov    $0x10000,%esi
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %ecx,%edx
call   1030 <tl880_write_regbits@plt>
jmp    1231 <tl880_dpc_video_sync_dvd+0x111>
mov    -0x8(%rbp),%rdi
mov    $0x10000,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <tl880_write_regbits@plt>
movq   $0x1,-0x10(%rbp)
jmp    129b <tl880_dpc_video_sync_dvd+0x17b>
cmpq   $0x3,0x2dea(%rip)
03
je     125a <tl880_dpc_video_sync_dvd+0x13a>
cmpq   $0x1,0x2ddc(%rip)
01
jne    1276 <tl880_dpc_video_sync_dvd+0x156>
mov    -0x8(%rbp),%rdi
mov    $0x10000,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <tl880_write_regbits@plt>
jmp    128e <tl880_dpc_video_sync_dvd+0x16e>
mov    -0x8(%rbp),%rdi
mov    $0x10000,%esi
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %ecx,%edx
call   1030 <tl880_write_regbits@plt>
movq   $0x0,-0x10(%rbp)
jmp    12c5 <tl880_dpc_video_sync_dvd+0x1a5>
cmpq   $0x0,0x2da5(%rip)
ja     12ae <tl880_dpc_video_sync_dvd+0x18e>
jmp    12c0 <tl880_dpc_video_sync_dvd+0x1a0>
mov    0x2d93(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2d88(%rip)
jmp    12c5 <tl880_dpc_video_sync_dvd+0x1a5>
movq   $0x0,-0x10(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tl880_dpc_video_sync_dvd>:
push   %rbx
addq   $0x1,0x2f17(%rip)
01
mov    %rdi,%rbx
xorb   $0x1,0x2efd(%rip)
mov    $0x10004,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1040 <tl880_read_regbits@plt>
test   %rax,%rax
sete   %al
mov    0x2edc(%rip),%rcx
and    $0xfffffffffffffffd,%rcx
cmp    $0x1,%rcx
sete   %cl
xor    %al,%cl
movzbl %cl,%r8d
mov    %rbx,%rdi
mov    $0x10000,%esi
xor    %edx,%edx
xor    %ecx,%ecx
pop    %rbx
jmp    1030 <tl880_write_regbits@plt>

LLVM IR (-O0):
%struct.tl880_dev = type { i32 }
@tl880_dpc_video_sync_dvd.val = internal global i64 1
@tl880_dpc_video_sync_dvd.field_select = internal global i64 0
@tl880_dpc_video_sync_dvd.delay_cnt = internal global i64 0
@tl880_dpc_video_sync_dvd.dpc_hsync_cnt = internal global i64 0
define void @tl880_dpc_video_sync_dvd(%struct.tl880_dev* %0) {
%2 = alloca %struct.tl880_dev*
%3 = alloca i64
store %struct.tl880_dev* %0, %struct.tl880_dev** %2
store i64 0, i64* %3
%4 = load i64, i64* @tl880_dpc_video_sync_dvd.dpc_hsync_cnt
%5 = add i64 %4, 1
store i64 %5, i64* @tl880_dpc_video_sync_dvd.dpc_hsync_cnt
br i1 false, label %6, label %18
6: ; preds = %1
br label %7
7: ; preds = %6
%8 = load i64, i64* @tl880_dpc_video_sync_dvd.field_select
%9 = xor i64 %8, 1
store i64 %9, i64* @tl880_dpc_video_sync_dvd.field_select
%10 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%11 = load i64, i64* @tl880_dpc_video_sync_dvd.field_select
%12 = trunc i64 %11 to i32
%13 = call i32 @tl880_write_regbits(%struct.tl880_dev* %10, i32 65536, i32 0, i32 0, i32 %12)
%14 = load i64, i64* @tl880_dpc_video_sync_dvd.field_select
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %7
store i64 0, i64* %3
br label %58
17: ; preds = %7
store i64 1, i64* %3
br label %50
18: ; preds = %1
%19 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%20 = xor i64 %19, 1
store i64 %20, i64* @tl880_dpc_video_sync_dvd.val
%21 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%22 = call i64 @tl880_read_regbits(%struct.tl880_dev* %21, i32 65540, i32 2, i32 2)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %18
%25 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%26 = icmp eq i64 %25, 3
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%29 = icmp eq i64 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %27, %24
%31 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%32 = call i32 @tl880_write_regbits(%struct.tl880_dev* %31, i32 65536, i32 0, i32 0, i32 1)
br label %36
33: ; preds = %27
%34 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%35 = call i32 @tl880_write_regbits(%struct.tl880_dev* %34, i32 65536, i32 0, i32 0, i32 0)
br label %36
36: ; preds = %33, %30
store i64 1, i64* %3
br label %50
37: ; preds = %18
%38 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%39 = icmp eq i64 %38, 3
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%42 = icmp eq i64 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %40, %37
%44 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%45 = call i32 @tl880_write_regbits(%struct.tl880_dev* %44, i32 65536, i32 0, i32 0, i32 0)
br label %49
46: ; preds = %40
%47 = load %struct.tl880_dev*, %struct.tl880_dev** %2
%48 = call i32 @tl880_write_regbits(%struct.tl880_dev* %47, i32 65536, i32 0, i32 0, i32 1)
br label %49
49: ; preds = %46, %43
store i64 0, i64* %3
br label %58
50: ; preds = %36, %17
%51 = load i64, i64* @tl880_dpc_video_sync_dvd.delay_cnt
%52 = icmp ule i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
br label %57
54: ; preds = %50
%55 = load i64, i64* @tl880_dpc_video_sync_dvd.delay_cnt
%56 = add i64 %55, -1
store i64 %56, i64* @tl880_dpc_video_sync_dvd.delay_cnt
br label %57
57: ; preds = %54, %53
br label %58
58: ; preds = %57, %49, %16
store i64 0, i64* %3
ret void
}

LLVM IR (-O2):
%struct.tl880_dev = type { i32 }
@tl880_dpc_video_sync_dvd.val = internal unnamed_addr global i64 1
@tl880_dpc_video_sync_dvd.dpc_hsync_cnt = internal unnamed_addr global i64 0
define void @tl880_dpc_video_sync_dvd(%struct.tl880_dev* %0) {
%2 = load i64, i64* @tl880_dpc_video_sync_dvd.dpc_hsync_cnt
%3 = add i64 %2, 1
store i64 %3, i64* @tl880_dpc_video_sync_dvd.dpc_hsync_cnt
%4 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%5 = xor i64 %4, 1
store i64 %5, i64* @tl880_dpc_video_sync_dvd.val
%6 = tail call i64 @tl880_read_regbits(%struct.tl880_dev* %0, i32 65540, i32 2, i32 2)
%7 = icmp eq i64 %6, 0
%8 = load i64, i64* @tl880_dpc_video_sync_dvd.val
%9 = and i64 %8, -3
%10 = icmp eq i64 %9, 1
%11 = xor i1 %10, %7
%12 = zext i1 %11 to i32
%13 = tail call i32 @tl880_write_regbits(%struct.tl880_dev* %0, i32 65536, i32 0, i32 0, i32 %12)
ret void
}