#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 */
scalar_t__ strlen(char *);
char *AppendChar(char *pszString, int iChar) {
  int iStrLength = (int)strlen(pszString);
  if (iStrLength == 0 || pszString[iStrLength - 1] != iChar) {
    pszString[iStrLength] = iChar;
    pszString[iStrLength + 1] = '\0';
  }
  return pszString;
}


x86 assembly (clang, -O0):
<AppendChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     114f <AppendChar+0x3f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    -0xc(%rbp),%eax
je     1170 <AppendChar+0x60>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AppendChar>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
shl    $0x20,%rcx
test   %eax,%eax
je     1141 <AppendChar+0x31>
movabs $0xffffffff00000000,%rax
ff ff ff
add    %rcx,%rax
sar    $0x20,%rax
movsbl (%rbx,%rax,1),%eax
cmp    %ebp,%eax
je     1161 <AppendChar+0x51>
mov    %rcx,%rax
sar    $0x20,%rax
mov    %bpl,(%rbx,%rax,1)
movabs $0x100000000,%rax
add    %rcx,%rax
sar    $0x20,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @AppendChar(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i32, i32* %4
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %11, %2
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %21, %11
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
define i8* @AppendChar(i8* returned %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, 0
%6 = shl i64 %3, 32
br i1 %5, label %14, label %7
7: ; preds = %2
%8 = add i64 %6, -4294967296
%9 = ashr exact i64 %8, 32
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, %1
br i1 %13, label %21, label %14
14: ; preds = %2, %7
%15 = trunc i32 %1 to i8
%16 = ashr exact i64 %6, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %15, i8* %17
%18 = add i64 %6, 4294967296
%19 = ashr exact i64 %18, 32
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %14, %7
ret i8* %0
}