#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 *);
int 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';
  }
  if (strlen(suffix) + strlen(keyname) > 8)
    return (*status = 206);
  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>
cltq
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1182 <ffkeyn+0x42>
cmpl   $0x0,-0x14(%rbp)
jge    1198 <ffkeyn+0x58>
mov    -0x28(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    1264 <ffkeyn+0x124>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xe55(%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    11e6 <ffkeyn+0xa6>
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    11f6 <ffkeyn+0xb6>
jmp    1213 <ffkeyn+0xd3>
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    11bd <ffkeyn+0x7d>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
cmp    $0x8,%eax
jle    124e <ffkeyn+0x10e>
mov    -0x28(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    1264 <ffkeyn+0x124>
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,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
movb   $0x0,(%rdx)
call   1040 <strlen@plt>
test   %ebp,%ebp
js     11bb <ffkeyn+0x7b>
mov    %eax,%r12d
test   %eax,%eax
je     11bb <ffkeyn+0x7b>
lea    0xe8f(%rip),%rdx
mov    %rsp,%rdi
mov    $0x10,%esi
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
movslq %r12d,%rax
xchg   %ax,%ax
cmpb   $0x20,-0x1(%rbx,%rax,1)
jne    11a2 <ffkeyn+0x62>
movb   $0x0,-0x1(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1190 <ffkeyn+0x50>
mov    %rsp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
cmp    $0x9,%eax
jl     11c9 <ffkeyn+0x89>
movl   $0xce,(%r14)
mov    $0xce,%eax
jmp    11d7 <ffkeyn+0x97>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    (%r14),%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 i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
store i64 %16, i64* %11
%17 = load i64, i64* %11
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19, %4
%23 = load i32*, i32** %9
store i32 206, i32* %23
store i32 206, i32* %5
br label %65
24: ; preds = %19
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%26 = load i32, i32* %7
%27 = call i32 @snprintf(i8* %25, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %8
%29 = load i8*, i8** %6
%30 = call i32 @strcpy(i8* %28, i8* %29)
br label %31
31: ; preds = %44, %24
%32 = load i64, i64* %11
%33 = icmp ugt i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i8*, i8** %8
%36 = load i64, i64* %11
%37 = sub i64 %36, 1
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 32
br label %42
42: ; preds = %34, %31
%43 = phi i1 [ false, %31 ], [ %41, %34 ]
br i1 %43, label %44, label %50
44: ; preds = %42
%45 = load i64, i64* %11
%46 = add i64 %45, -1
store i64 %46, i64* %11
%47 = load i8*, i8** %8
%48 = load i64, i64* %11
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 0, i8* %49
br label %31
50: ; preds = %42
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = load i8*, i8** %8
%54 = call i32 @strlen(i8* %53)
%55 = add nsw i32 %52, %54
%56 = icmp sgt i32 %55, 8
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = load i32*, i32** %9
store i32 206, i32* %58
store i32 206, i32* %5
br label %65
59: ; preds = %50
%60 = load i8*, i8** %8
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%62 = call i32 @strcat(i8* %60, i8* %61)
%63 = load i32*, i32** %9
%64 = load i32, i32* %63
store i32 %64, i32* %5
br label %65
65: ; preds = %59, %57, %22
%66 = load i32, i32* %5
ret i32 %66
}

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 i32 @strlen(i8* %0)
%8 = icmp eq i32 %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 %33
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)
%15 = sext i32 %7 to i64
br label %16
16: ; preds = %12, %22
%17 = phi i64 [ %18, %22 ], [ %15, %12 ]
%18 = add i64 %17, -1
%19 = getelementptr inbounds i8, i8* %2, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 32
br i1 %21, label %22, label %24
22: ; preds = %16
store i8 0, i8* %19
%23 = icmp eq i64 %18, 0
br i1 %23, label %24, label %16
24: ; preds = %16, %22
%25 = call i32 @strlen(i8* %6)
%26 = call i32 @strlen(i8* %2)
%27 = add nsw i32 %26, %25
%28 = icmp sgt i32 %27, 8
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 206, i32* %3
br label %33
30: ; preds = %24
%31 = call i32 @strcat(i8* %2, i8* %6)
%32 = load i32, i32* %3
br label %33
33: ; preds = %30, %29, %11
%34 = phi i32 [ 206, %11 ], [ 206, %29 ], [ %32, %30 ]
ret i32 %34
}