#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*/ check_tbuf(int, unsigned int);
int /*<<< orphan*/ report_device(int);
dsu3_tb_check(int dsuaddr) {
  int i, tmp, atmp, k, j, histlen;
  unsigned int ahblen;
  int pat5 = 0x55555555;
  int patA = 0xAAAAAAAA;
  int err = 0;
  volatile int xtmp = 2;
  volatile int vtmp = 0;
  report_device(0x01004000);
  *((volatile int *)(dsuaddr + 0x000040)) = 0xffff0000;
  ahblen = *((volatile int *)(dsuaddr + 0x000040));
  ahblen = (ahblen >> 14);
  if (ahblen) {
    check_tbuf(dsuaddr + 0x200000, ahblen + 1);
  }
  *((volatile int *)(dsuaddr + 0x110000)) = 0x0000ffff;
  ahblen = *((volatile int *)(dsuaddr + 0x110000));
  if (ahblen) {
    check_tbuf(dsuaddr + 0x100000, ahblen + 1);
  }
}


x86 assembly (clang, -O0):
<dsu3_tb_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x55555555,-0x28(%rbp)
movl   $0xaaaaaaaa,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x2,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    $0x1004000,%edi
call   1030 <report_device@plt>
mov    -0x8(%rbp),%eax
add    $0x40,%eax
cltq
movl   $0xffff0000,(%rax)
mov    -0x8(%rbp),%eax
add    $0x40,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shr    $0xe,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     119a <dsu3_tb_check+0x7a>
mov    -0x8(%rbp),%edi
add    $0x200000,%edi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   1040 <check_tbuf@plt>
mov    -0x8(%rbp),%eax
add    $0x110000,%eax
cltq
movl   $0xffff,(%rax)
mov    -0x8(%rbp),%eax
add    $0x110000,%eax
cltq
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11d7 <dsu3_tb_check+0xb7>
mov    -0x8(%rbp),%edi
add    $0x100000,%edi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   1040 <check_tbuf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsu3_tb_check>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
movl   $0x2,0x4(%rsp)
movl   $0x0,(%rsp)
mov    $0x1004000,%edi
call   1030 <report_device@plt>
movslq %r14d,%rbx
movl   $0xffff0000,0x40(%rbx)
mov    0x40(%rbx),%esi
cmp    $0x4000,%esi
jb     1167 <dsu3_tb_check+0x47>
shr    $0xe,%esi
lea    0x200000(%r14),%edi
add    $0x1,%esi
call   1040 <check_tbuf@plt>
movl   $0xffff,0x110000(%rbx)
mov    0x110000(%rbx),%esi
test   %esi,%esi
je     118d <dsu3_tb_check+0x6d>
add    $0x100000,%r14d
add    $0x1,%esi
mov    %r14d,%edi
call   1040 <check_tbuf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @dsu3_tb_check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %3
store i32 1431655765, i32* %11
store i32 -1431655766, i32* %12
store i32 0, i32* %13
store volatile i32 2, i32* %14
store volatile i32 0, i32* %15
%16 = call i32 @report_device(i32 16793600)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 64
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
store volatile i32 -65536, i32* %20
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 64
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load volatile i32, i32* %24
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = lshr i32 %26, 14
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %1
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 2097152
%33 = load i32, i32* %10
%34 = add i32 %33, 1
%35 = call i32 @check_tbuf(i32 %32, i32 %34)
br label %36
36: ; preds = %30, %1
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1114112
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i32*
store volatile i32 65535, i32* %40
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1114112
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
%45 = load volatile i32, i32* %44
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %36
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1048576
%51 = load i32, i32* %10
%52 = add i32 %51, 1
%53 = call i32 @check_tbuf(i32 %50, i32 %52)
br label %54
54: ; preds = %48, %36
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
define i32 @dsu3_tb_check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store volatile i32 2, i32* %2
%5 = bitcast i32* %3 to i8*
store volatile i32 0, i32* %3
%6 = tail call i32 @report_device(i32 16793600)
%7 = add nsw i32 %0, 64
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
store volatile i32 -65536, i32* %9
%10 = load volatile i32, i32* %9
%11 = icmp ult i32 %10, 16384
br i1 %11, label %17, label %12
12: ; preds = %1
%13 = lshr i32 %10, 14
%14 = add nsw i32 %0, 2097152
%15 = add nuw nsw i32 %13, 1
%16 = tail call i32 @check_tbuf(i32 %14, i32 %15)
br label %17
17: ; preds = %12, %1
%18 = add nsw i32 %0, 1114112
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
store volatile i32 65535, i32* %20
%21 = load volatile i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = add nsw i32 %0, 1048576
%25 = add i32 %21, 1
%26 = tail call i32 @check_tbuf(i32 %24, i32 %25)
br label %27
27: ; preds = %23, %17
ret i32 undef
}