#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*/ cmdAdd(char const);
int /*<<< orphan*/ cmdPut();
int /*<<< orphan*/ cmdSubtract(int);
int strlen(char const *);
void cmdPutText(const char *sText) {
  int iPos, iOld;
  iOld = 0;
  for (iPos = 0; iPos < strlen(sText); iPos++) {
    if (sText[iPos] > iOld)
      cmdAdd(sText[iPos] - iOld);
    else if (sText[iPos] < iOld)
      cmdSubtract(iOld - sText[iPos]);
    cmdPut();
    iOld = sText[iPos];
  }
  cmdSubtract(iOld);
}


x86 assembly (clang, -O0):
<cmdPutText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11fb <cmdPutText+0xbb>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    -0x10(%rbp),%eax
jle    11a7 <cmdPutText+0x67>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    -0x10(%rbp),%eax
movsbl %al,%edi
call   1050 <cmdAdd@plt>
jmp    11d7 <cmdPutText+0x97>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    -0x10(%rbp),%eax
jge    11d2 <cmdPutText+0x92>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    %eax,%edi
call   1040 <cmdSubtract@plt>
jmp    11d7 <cmdPutText+0x97>
mov    $0x0,%al
call   1060 <cmdPut@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <cmdPutText+0x1a>
mov    -0x10(%rbp),%edi
call   1040 <cmdSubtract@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdPutText>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    119e <cmdPutText+0x5e>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    118a <cmdPutText+0x4a>
cs nopw 0x0(%rax,%rax,1)
sub    %bpl,%al
movsbl %al,%edi
call   1050 <cmdAdd@plt>
xor    %eax,%eax
call   1060 <cmdPut@plt>
movsbl (%r14,%rbx,1),%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a0 <cmdPutText+0x60>
movsbl (%r14,%rbx,1),%eax
mov    %ebp,%edi
sub    %eax,%edi
jl     1160 <cmdPutText+0x20>
jle    116b <cmdPutText+0x2b>
call   1040 <cmdSubtract@plt>
jmp    116b <cmdPutText+0x2b>
xor    %ebp,%ebp
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <cmdSubtract@plt>

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

LLVM IR (-O2):
define void @cmdPutText(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %30
4: ; preds = %1, %20
%5 = phi i64 [ %24, %20 ], [ 0, %1 ]
%6 = phi i32 [ %23, %20 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp slt i32 %6, %9
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = trunc i32 %6 to i8
%13 = sub i8 %8, %12
%14 = tail call i32 @cmdAdd(i8 signext %13)
br label %20
15: ; preds = %4
%16 = icmp sgt i32 %6, %9
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = sub nsw i32 %6, %9
%19 = tail call i32 @cmdSubtract(i32 %18)
br label %20
20: ; preds = %15, %17, %11
%21 = tail call i32 (...) @cmdPut()
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = add nuw nsw i64 %5, 1
%25 = tail call i32 @strlen(i8* %0)
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %4, label %28
28: ; preds = %20
%29 = sext i8 %22 to i32
br label %30
30: ; preds = %28, %1
%31 = phi i32 [ 0, %1 ], [ %29, %28 ]
%32 = tail call i32 @cmdSubtract(i32 %31)
ret void
}