#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*/ getPT_sync();
int /*<<< orphan*/ putCMD(int);
int /*<<< orphan*/ putPT(int);
int /*<<< orphan*/ putPT_BLK(unsigned char *, int);
int /*<<< orphan*/ putPT_flash();
int _dos_putstring_console(char *str, int size) {
  int len;
  int ct;
  int start;
  start = 1;
  if (size == 0) {
    char *p;
    p = str;
    while (*p)
      ++p;
    size = p - str;
  }
  len = size;
  while (len) {
    if (len > 0x80) {
      ct = 0x80;
    } else {
      ct = len;
    }
    if (start) {
      putCMD(ct - 1);
      start = 0;
    } else {
      putPT(ct - 1);
    }
    getPT_sync();
    putPT_BLK((unsigned char *)str, ct);
    len -= ct;
    str += ct;
  }
  putPT_flash();
  return size;
}


x86 assembly (clang, -O0):
<_dos_putstring_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11a4 <_dos_putstring_console+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1196 <_dos_putstring_console+0x46>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1178 <_dos_putstring_console+0x28>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1233 <_dos_putstring_console+0xe3>
cmpl   $0x80,-0x10(%rbp)
jle    11cd <_dos_putstring_console+0x7d>
movl   $0x80,-0x14(%rbp)
jmp    11d3 <_dos_putstring_console+0x83>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f4 <_dos_putstring_console+0xa4>
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
call   1050 <putCMD@plt>
movl   $0x0,-0x18(%rbp)
jmp    11ff <_dos_putstring_console+0xaf>
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
call   1030 <putPT@plt>
mov    $0x0,%al
call   1060 <getPT_sync@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <putPT_BLK@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <_dos_putstring_console+0x5a>
mov    $0x0,%al
call   1070 <putPT_flash@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dos_putstring_console>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
test   %esi,%esi
jne    1182 <_dos_putstring_console+0x32>
mov    $0xffffffff,%r15d
mov    %r12,%rax
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1170 <_dos_putstring_console+0x20>
test   %r15d,%r15d
je     11f3 <_dos_putstring_console+0xa3>
cmp    $0x80,%r15d
mov    $0x80,%r14d
cmovl  %r15d,%r14d
lea    -0x1(%r14),%edi
call   1050 <putCMD@plt>
xor    %eax,%eax
call   1060 <getPT_sync@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1040 <putPT_BLK@plt>
mov    %r15d,%ebx
sub    %r14d,%ebx
je     11f6 <_dos_putstring_console+0xa6>
movslq %r14d,%rax
add    %rax,%r12
nopl   0x0(%rax)
cmp    $0x80,%ebx
mov    $0x80,%ebp
cmovl  %ebx,%ebp
lea    -0x1(%rbp),%edi
call   1030 <putPT@plt>
xor    %eax,%eax
call   1060 <getPT_sync@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <putPT_BLK@plt>
movslq %ebp,%rax
add    %rax,%r12
sub    %eax,%ebx
jne    11c0 <_dos_putstring_console+0x70>
jmp    11f6 <_dos_putstring_console+0xa6>
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <putPT_flash@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_dos_putstring_console(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i8*, i8** %3
store i8* %12, i8** %8
br label %13
13: ; preds = %17, %11
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %8
br label %13
20: ; preds = %13
%21 = load i8*, i8** %8
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %4
br label %27
27: ; preds = %20, %2
%28 = load i32, i32* %4
store i32 %28, i32* %5
br label %29
29: ; preds = %49, %27
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 128
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 128, i32* %6
br label %38
36: ; preds = %32
%37 = load i32, i32* %5
store i32 %37, i32* %6
br label %38
38: ; preds = %36, %35
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = call i32 @putCMD(i32 %43)
store i32 0, i32* %7
br label %49
45: ; preds = %38
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 1
%48 = call i32 @putPT(i32 %47)
br label %49
49: ; preds = %45, %41
%50 = call i32 (...) @getPT_sync()
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = call i32 @putPT_BLK(i8* %51, i32 %52)
%54 = load i32, i32* %6
%55 = load i32, i32* %5
%56 = sub nsw i32 %55, %54
store i32 %56, i32* %5
%57 = load i32, i32* %6
%58 = load i8*, i8** %3
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %3
br label %29
61: ; preds = %29
%62 = call i32 (...) @putPT_flash()
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
define i32 @_dos_putstring_console(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi i8* [ %8, %4 ], [ %0, %2 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %9, label %4
9: ; preds = %4
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %41, label %15
15: ; preds = %2, %9
%16 = phi i32 [ %13, %9 ], [ %1, %2 ]
%17 = icmp slt i32 %16, 128
%18 = select i1 %17, i32 %16, i32 128
%19 = add nsw i32 %18, -1
%20 = tail call i32 @putCMD(i32 %19)
%21 = tail call i32 (...) @getPT_sync()
%22 = tail call i32 @putPT_BLK(i8* %0, i32 %18)
%23 = sub nsw i32 %16, %18
%24 = icmp eq i32 %23, 0
br i1 %24, label %41, label %25
25: ; preds = %15
%26 = sext i32 %18 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
br label %28
28: ; preds = %25, %28
%29 = phi i32 [ %37, %28 ], [ %23, %25 ]
%30 = phi i8* [ %39, %28 ], [ %27, %25 ]
%31 = icmp slt i32 %29, 128
%32 = select i1 %31, i32 %29, i32 128
%33 = add nsw i32 %32, -1
%34 = tail call i32 @putPT(i32 %33)
%35 = tail call i32 (...) @getPT_sync()
%36 = tail call i32 @putPT_BLK(i8* %30, i32 %32)
%37 = sub nsw i32 %29, %32
%38 = sext i32 %32 to i64
%39 = getelementptr inbounds i8, i8* %30, i64 %38
%40 = icmp eq i32 %37, 0
br i1 %40, label %41, label %28
41: ; preds = %28, %15, %9
%42 = phi i32 [ 0, %9 ], [ %16, %15 ], [ %16, %28 ]
%43 = tail call i32 (...) @putPT_flash()
ret i32 %42
}