#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*/ Dbg(int, int, char *);
int strlen(char *);
void StringAppendChar(char *r, int maxlen, int c) {
  int len;
  len = strlen(r);
  if (len >= (maxlen - 1)) {
    Dbg(0x80, 1, "StringAppendChar: maxlen");
    return;
  }
  r[len] = c;
  r[len + 1] = '\0';
}


x86 assembly (clang, -O0):
<StringAppendChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     116a <StringAppendChar+0x4a>
mov    $0x80,%edi
mov    $0x1,%esi
lea    0xea0(%rip),%rdx
call   1040 <Dbg@plt>
jmp    118b <StringAppendChar+0x6b>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringAppendChar>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jge    1148 <StringAppendChar+0x28>
cltq
mov    %r14b,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xeb1(%rip),%rdx
mov    $0x80,%edi
mov    $0x1,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <Dbg@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"StringAppendChar: maxlen\00"
define void @StringAppendChar(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = icmp sge i32 %10, %12
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @Dbg(i32 128, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %28
16: ; preds = %3
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %16, %14
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"StringAppendChar: maxlen\00"
define void @StringAppendChar(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %1, -1
%6 = icmp slt i32 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @Dbg(i32 128, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %3
%10 = trunc i32 %2 to i8
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %10, i8* %12
%13 = add nsw i32 %4, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %9, %7
ret void
}