#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__ log10(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char, int);
int /*<<< orphan*/ strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strtrm(char *, int, char const *);
const char *continuation_key(char buffer[], unsigned long buflen,
                             const char *key, int depth) {
  const char *value;
  char newkey[64 + 1];
  if (depth < 1)
    value = key;
  else {
    strtrm(newkey, 64 + 1, key);
    if (((strlen(newkey) + 2 + (int)log10(depth)) < buflen) &&
        (!(strchr(newkey, '~')))) {
      sprintf(buffer, "%s%c%u", newkey, '~', depth);
      value = buffer;
    } else {
      value = (const char *)NULL;
    }
  }
  return (value);
}


x86 assembly (clang, -O0):
<continuation_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1181 <continuation_key+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    120c <continuation_key+0xbc>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x41,%esi
call   1050 <strtrm@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x74(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <log10@plt>
mov    %rax,%rcx
mov    -0x74(%rbp),%eax
add    %ecx,%eax
cltq
cmp    -0x10(%rbp),%rax
jae    11ff <continuation_key+0xaf>
lea    -0x70(%rbp),%rdi
mov    $0x7e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
jne    11ff <continuation_key+0xaf>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0x1c(%rbp),%r8d
lea    0xe18(%rip),%rsi
mov    $0x7e,%ecx
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1207 <continuation_key+0xb7>
movq   $0x0,-0x28(%rbp)
jmp    120c <continuation_key+0xbc>
mov    -0x28(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<continuation_key>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
test   %ecx,%ecx
jle    11ab <continuation_key+0x5b>
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x41,%esi
call   1050 <strtrm@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <log10@plt>
add    %ebx,%eax
add    $0x2,%eax
cltq
cmp    %r14,%rax
jae    11a6 <continuation_key+0x56>
mov    %rsp,%rdi
mov    $0x7e,%esi
call   1040 <strchr@plt>
test   %eax,%eax
je     11b0 <continuation_key+0x60>
xor    %r12d,%r12d
jmp    11ca <continuation_key+0x7a>
mov    %rdx,%r12
jmp    11ca <continuation_key+0x7a>
lea    0xe49(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
mov    $0x7e,%ecx
mov    %ebp,%r8d
call   1070 <sprintf@plt>
mov    %r12,%rax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%c%u\00"
define i8* @continuation_key(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [65 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = load i8*, i8** %7
store i8* %14, i8** %9
br label %41
15: ; preds = %4
%16 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %7
%18 = call i32 @strtrm(i8* %16, i32 65, i8* %17)
%19 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 2
%22 = load i32, i32* %8
%23 = call i64 @log10(i32 %22)
%24 = trunc i64 %23 to i32
%25 = add nsw i32 %21, %24
%26 = sext i32 %25 to i64
%27 = load i64, i64* %6
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %15
%30 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%31 = call i32 @strchr(i8* %30, i8 signext 126)
%32 = icmp ne i32 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [65 x i8], [65 x i8]* %10, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %35, i8 signext 126, i32 %36)
%38 = load i8*, i8** %5
store i8* %38, i8** %9
br label %40
39: ; preds = %29, %15
store i8* null, i8** %9
br label %40
40: ; preds = %39, %33
br label %41
41: ; preds = %40, %13
%42 = load i8*, i8** %9
ret i8* %42
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%c%u\00"
define i8* @continuation_key(i8* writeonly %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca [65 x i8]
%6 = getelementptr inbounds [65 x i8], [65 x i8]* %5, i64 0, i64 0
%7 = icmp slt i32 %3, 1
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = call i32 @strtrm(i8* %6, i32 65, i8* %2)
%10 = call i32 @strlen(i8* %6)
%11 = add nsw i32 %10, 2
%12 = call i64 @log10(i32 %3)
%13 = trunc i64 %12 to i32
%14 = add nsw i32 %11, %13
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %15, %1
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = call i32 @strchr(i8* %6, i8 signext 126)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6, i8 signext 126, i32 %3)
br label %22
22: ; preds = %8, %17, %4, %20
%23 = phi i8* [ %0, %20 ], [ %2, %4 ], [ null, %17 ], [ null, %8 ]
ret i8* %23
}