#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 */
size_t strlen(char *);
int zsnprintf(char *, size_t, char *, char);
int canon_path_add_suffix(char *base, size_t out_len, char suffix) {
  size_t cbase_len;
  cbase_len = strlen(base);
  if (cbase_len < 2)
    return zsnprintf(base, out_len, "%c", suffix);
  return zsnprintf(base + cbase_len, out_len - cbase_len, "%c", suffix);
}


x86 assembly (clang, -O0):
<canon_path_add_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x2,-0x28(%rbp)
jae    116d <canon_path_add_suffix+0x4d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xea4(%rip),%rdx
movsbl -0x19(%rbp),%ecx
call   1040 <zsnprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1190 <canon_path_add_suffix+0x70>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
lea    0xe7c(%rip),%rdx
movsbl -0x19(%rbp),%ecx
call   1040 <zsnprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canon_path_add_suffix>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x1,%rax
jbe    113d <canon_path_add_suffix+0x1d>
add    %rax,%rbx
sub    %rax,%r14
movsbl %bpl,%ecx
lea    0xeb8(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <zsnprintf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define i32 @canon_path_add_suffix(i8* %0, i64 %1, i8 signext %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ult i64 %4, 2
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @zsnprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %2)
br label %12
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %0, i64 %4
%10 = sub i64 %1, %4
%11 = tail call i32 @zsnprintf(i8* %9, i64 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %2)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %7, %6 ], [ %11, %8 ]
ret i32 %13
}