#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*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
int ffkeyn(const char *keyroot, int value, char *keyname, int *status) {
  char suffix[16];
  size_t rootlen;
  keyname[0] = '\0';
  rootlen = strlen(keyroot);
  if (rootlen == 0 || value < 0)
    return (*status = 206);
  snprintf(suffix, 16, "%d", value);
  strcpy(keyname, keyroot);
  while (rootlen > 0 && keyname[rootlen - 1] == ' ') {
    rootlen--;
    keyname[rootlen] = '\0';
  }
  strcat(keyname, suffix);
  return (*status);
}


x86 assembly (clang, -O0):
<ffkeyn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1180 <ffkeyn+0x40>
cmpl   $0x0,-0x14(%rbp)
jge    1196 <ffkeyn+0x56>
mov    -0x28(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    1227 <ffkeyn+0xe7>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xe57(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x49(%rbp)
jbe    11e4 <ffkeyn+0xa4>
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11f4 <ffkeyn+0xb4>
jmp    1211 <ffkeyn+0xd1>
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bb <ffkeyn+0x7b>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffkeyn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
movb   $0x0,(%rdx)
call   1040 <strlen@plt>
test   %ebp,%ebp
js     11b4 <ffkeyn+0x74>
mov    %rax,%rbx
test   %rax,%rax
je     11b4 <ffkeyn+0x74>
lea    0xe8e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x10,%esi
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
nopl   0x0(%rax)
cmpb   $0x20,-0x1(%r15,%rbx,1)
jne    11a4 <ffkeyn+0x64>
movb   $0x0,-0x1(%r15,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1190 <ffkeyn+0x50>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    (%r14),%eax
jmp    11c0 <ffkeyn+0x80>
movl   $0xce,(%r14)
mov    $0xce,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @ffkeyn(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [16 x i8]
%11 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i8*, i8** %8
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %11
%16 = load i64, i64* %11
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %4
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %4
%22 = load i32*, i32** %9
store i32 206, i32* %22
store i32 206, i32* %5
br label %55
23: ; preds = %18
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%25 = load i32, i32* %7
%26 = call i32 @snprintf(i8* %24, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %8
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
br label %30
30: ; preds = %43, %23
%31 = load i64, i64* %11
%32 = icmp ugt i64 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i64, i64* %11
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 32
br label %41
41: ; preds = %33, %30
%42 = phi i1 [ false, %30 ], [ %40, %33 ]
br i1 %42, label %43, label %49
43: ; preds = %41
%44 = load i64, i64* %11
%45 = add i64 %44, -1
store i64 %45, i64* %11
%46 = load i8*, i8** %8
%47 = load i64, i64* %11
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 0, i8* %48
br label %30
49: ; preds = %41
%50 = load i8*, i8** %8
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i32*, i32** %9
%54 = load i32, i32* %53
store i32 %54, i32* %5
br label %55
55: ; preds = %49, %21
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @ffkeyn(i8* %0, i32 %1, i8* %2, i32* nocapture %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
store i8 0, i8* %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = icmp eq i64 %7, 0
%9 = icmp slt i32 %1, 0
%10 = or i1 %9, %8
br i1 %10, label %11, label %12
11: ; preds = %4
store i32 206, i32* %3
br label %26
12: ; preds = %4
%13 = call i32 @snprintf(i8* %6, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%14 = call i32 @strcpy(i8* %2, i8* %0)
br label %15
15: ; preds = %12, %21
%16 = phi i64 [ %7, %12 ], [ %17, %21 ]
%17 = add i64 %16, -1
%18 = getelementptr inbounds i8, i8* %2, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 32
br i1 %20, label %21, label %23
21: ; preds = %15
store i8 0, i8* %18
%22 = icmp eq i64 %17, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %21
%24 = call i32 @strcat(i8* %2, i8* %6)
%25 = load i32, i32* %3
br label %26
26: ; preds = %23, %11
%27 = phi i32 [ 206, %11 ], [ %25, %23 ]
ret i32 %27
}