#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*/ b1_put_byte(unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ b1_put_word(unsigned int, unsigned int);
int /*<<< orphan*/ outsb(unsigned int, unsigned char *, unsigned int);
int t1_fifostatus(unsigned int);
scalar_t__ t1_isfastlink(unsigned int);
void t1_put_slice(unsigned int base, unsigned char *dp, unsigned int len) {
  unsigned i = len;
  b1_put_word(base, i);
  if (t1_isfastlink(base)) {
    int status;
    while (i > 0) {
      status = t1_fifostatus(base) & (0x10 | 0x20);
      if (i >= 256)
        status |= 0x40;
      switch (status) {
      case 0x10 | 0x20 | 0x40:
        outsb(base + 0x01, dp, 256);
        dp += 256;
        i -= 256;
        break;
      case 0x10 | 0x20:
        outsb(base + 0x01, dp, i);
        dp += i;
        i = 0;
        break;
      default:
        b1_put_byte(base, *dp++);
        i--;
        break;
      }
    }
  } else {
    while (i-- > 0)
      b1_put_byte(base, *dp++);
  }
}


x86 assembly (clang, -O0):
<t1_put_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <b1_put_word@plt>
mov    -0x4(%rbp),%edi
call   1040 <t1_isfastlink@plt>
cmp    $0x0,%rax
je     126a <t1_put_slice+0x11a>
jmp    118a <t1_put_slice+0x3a>
cmpl   $0x0,-0x18(%rbp)
jbe    1265 <t1_put_slice+0x115>
mov    -0x4(%rbp),%edi
call   1030 <t1_fifostatus@plt>
and    $0x30,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x100,-0x18(%rbp)
jb     11b8 <t1_put_slice+0x68>
mov    -0x1c(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x30,%eax
je     120f <t1_put_slice+0xbf>
jmp    11cc <t1_put_slice+0x7c>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
jne    123d <t1_put_slice+0xed>
jmp    11dd <t1_put_slice+0x8d>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1070 <outsb@plt>
mov    -0x10(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x100,%eax
mov    %eax,-0x18(%rbp)
jmp    1260 <t1_put_slice+0x110>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <outsb@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1260 <t1_put_slice+0x110>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1060 <b1_put_byte@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    118a <t1_put_slice+0x3a>
jmp    12a7 <t1_put_slice+0x157>
jmp    126f <t1_put_slice+0x11f>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
jbe    12a2 <t1_put_slice+0x152>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1060 <b1_put_byte@plt>
jmp    126f <t1_put_slice+0x11f>
jmp    12a7 <t1_put_slice+0x157>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t1_put_slice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %edx,%esi
call   1050 <b1_put_word@plt>
mov    %r14d,%edi
call   1040 <t1_isfastlink@plt>
test   %rax,%rax
je     11eb <t1_put_slice+0x9b>
test   %ebp,%ebp
je     1215 <t1_put_slice+0xc5>
lea    0x1(%r14),%r15d
jmp    11b0 <t1_put_slice+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <outsb@plt>
add    $0x100,%rbx
mov    $0xffffff00,%eax
add    %eax,%ebp
je     1215 <t1_put_slice+0xc5>
mov    %r14d,%edi
call   1030 <t1_fifostatus@plt>
and    $0x30,%eax
lea    0x40(%rax),%ecx
cmp    $0x100,%ebp
cmovb  %eax,%ecx
cmp    $0x70,%ecx
je     1190 <t1_put_slice+0x40>
cmp    $0x30,%ecx
je     1220 <t1_put_slice+0xd0>
movzbl (%rbx),%esi
add    $0x1,%rbx
mov    %r14d,%edi
call   1060 <b1_put_byte@plt>
mov    $0xffffffff,%eax
add    %eax,%ebp
jne    11b0 <t1_put_slice+0x60>
jmp    1215 <t1_put_slice+0xc5>
test   %ebp,%ebp
je     1215 <t1_put_slice+0xc5>
mov    %ebp,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rbp,1),%esi
mov    %r14d,%edi
call   1060 <b1_put_byte@plt>
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    1200 <t1_put_slice+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <outsb@plt>

LLVM IR (-O0):
define void @t1_put_slice(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
store i32 %9, i32* %7
%10 = load i32, i32* %4
%11 = load i32, i32* %7
%12 = call i32 @b1_put_word(i32 %10, i32 %11)
%13 = load i32, i32* %4
%14 = call i64 @t1_isfastlink(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %61
16: ; preds = %3
br label %17
17: ; preds = %59, %16
%18 = load i32, i32* %7
%19 = icmp ugt i32 %18, 0
br i1 %19, label %20, label %60
20: ; preds = %17
%21 = load i32, i32* %4
%22 = call i32 @t1_fifostatus(i32 %21)
%23 = and i32 %22, 48
store i32 %23, i32* %8
%24 = load i32, i32* %7
%25 = icmp uge i32 %24, 256
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* %8
%28 = or i32 %27, 64
store i32 %28, i32* %8
br label %29
29: ; preds = %26, %20
%30 = load i32, i32* %8
switch i32 %30, label %50 [
i32 112, label %31
i32 48, label %40
]
31: ; preds = %29
%32 = load i32, i32* %4
%33 = add i32 %32, 1
%34 = load i8*, i8** %5
%35 = call i32 @outsb(i32 %33, i8* %34, i32 256)
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 256
store i8* %37, i8** %5
%38 = load i32, i32* %7
%39 = sub i32 %38, 256
store i32 %39, i32* %7
br label %59
40: ; preds = %29
%41 = load i32, i32* %4
%42 = add i32 %41, 1
%43 = load i8*, i8** %5
%44 = load i32, i32* %7
%45 = call i32 @outsb(i32 %42, i8* %43, i32 %44)
%46 = load i32, i32* %7
%47 = load i8*, i8** %5
%48 = zext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %5
store i32 0, i32* %7
br label %59
50: ; preds = %29
%51 = load i32, i32* %4
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %5
%54 = load i8, i8* %52
%55 = zext i8 %54 to i32
%56 = call i32 @b1_put_byte(i32 %51, i32 %55)
%57 = load i32, i32* %7
%58 = add i32 %57, -1
store i32 %58, i32* %7
br label %59
59: ; preds = %50, %40, %31
br label %17
60: ; preds = %17
br label %74
61: ; preds = %3
br label %62
62: ; preds = %66, %61
%63 = load i32, i32* %7
%64 = add i32 %63, -1
store i32 %64, i32* %7
%65 = icmp ugt i32 %63, 0
br i1 %65, label %66, label %73
66: ; preds = %62
%67 = load i32, i32* %4
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %5
%70 = load i8, i8* %68
%71 = zext i8 %70 to i32
%72 = call i32 @b1_put_byte(i32 %67, i32 %71)
br label %62
73: ; preds = %62
br label %74
74: ; preds = %73, %60
ret void
}

LLVM IR (-O2):
define void @t1_put_slice(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @b1_put_word(i32 %0, i32 %2)
%5 = tail call i64 @t1_isfastlink(i32 %0)
%6 = icmp eq i64 %5, 0
%7 = icmp eq i32 %2, 0
br i1 %6, label %11, label %8
8: ; preds = %3
br i1 %7, label %44, label %9
9: ; preds = %8
%10 = add i32 %0, 1
br label %12
11: ; preds = %3
br i1 %7, label %44, label %35
12: ; preds = %9, %30
%13 = phi i32 [ %2, %9 ], [ %33, %30 ]
%14 = phi i8* [ %1, %9 ], [ %32, %30 ]
%15 = tail call i32 @t1_fifostatus(i32 %0)
%16 = and i32 %15, 48
%17 = icmp ugt i32 %13, 255
%18 = or i32 %16, 64
%19 = select i1 %17, i32 %18, i32 %16
switch i32 %19, label %25 [
i32 112, label %20
i32 48, label %23
]
20: ; preds = %12
%21 = tail call i32 @outsb(i32 %10, i8* %14, i32 256)
%22 = getelementptr inbounds i8, i8* %14, i64 256
br label %30
23: ; preds = %12
%24 = tail call i32 @outsb(i32 %10, i8* %14, i32 %13)
br label %44
25: ; preds = %12
%26 = getelementptr inbounds i8, i8* %14, i64 1
%27 = load i8, i8* %14
%28 = zext i8 %27 to i32
%29 = tail call i32 @b1_put_byte(i32 %0, i32 %28)
br label %30
30: ; preds = %25, %20
%31 = phi i32 [ -1, %25 ], [ -256, %20 ]
%32 = phi i8* [ %26, %25 ], [ %22, %20 ]
%33 = add i32 %13, %31
%34 = icmp eq i32 %33, 0
br i1 %34, label %44, label %12
35: ; preds = %11, %35
%36 = phi i32 [ %38, %35 ], [ %2, %11 ]
%37 = phi i8* [ %39, %35 ], [ %1, %11 ]
%38 = add i32 %36, -1
%39 = getelementptr inbounds i8, i8* %37, i64 1
%40 = load i8, i8* %37
%41 = zext i8 %40 to i32
%42 = tail call i32 @b1_put_byte(i32 %0, i32 %41)
%43 = icmp eq i32 %38, 0
br i1 %43, label %44, label %35
44: ; preds = %30, %35, %23, %8, %11
ret void
}