#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*/ sprintf(char *, 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 || rootlen > 7 || value < 0)
    return (*status = 206);
  sprintf(suffix, "%d", value);
  if (strlen(suffix) + rootlen > 8)
    return (*status = 206);
  strcpy(keyname, keyroot);
  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     118b <ffkeyn+0x4b>
cmpq   $0x7,-0x48(%rbp)
ja     118b <ffkeyn+0x4b>
cmpl   $0x0,-0x14(%rbp)
jge    11a1 <ffkeyn+0x61>
mov    -0x28(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    1204 <ffkeyn+0xc4>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe51(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x48(%rbp),%rax
cmp    $0x8,%rax
jbe    11e1 <ffkeyn+0xa1>
mov    -0x28(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    1204 <ffkeyn+0xc4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
movb   $0x0,(%rdx)
call   1040 <strlen@plt>
test   %ebp,%ebp
js     1197 <ffkeyn+0x57>
mov    %rax,%rbx
add    $0xfffffffffffffff8,%rax
cmp    $0xfffffffffffffff8,%rax
jbe    1197 <ffkeyn+0x57>
lea    0xe87(%rip),%rsi
mov    %rsp,%r13
mov    %r13,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
cmp    $0x9,%rax
jb     11a5 <ffkeyn+0x65>
movl   $0xce,(%r14)
mov    $0xce,%eax
jmp    11be <ffkeyn+0x7e>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    (%r14),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 %24, label %18
18: ; preds = %4
%19 = load i64, i64* %11
%20 = icmp ugt i64 %19, 7
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21, %18, %4
%25 = load i32*, i32** %9
store i32 206, i32* %25
store i32 206, i32* %5
br label %46
26: ; preds = %21
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%28 = load i32, i32* %7
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%31 = call i64 @strlen(i8* %30)
%32 = load i64, i64* %11
%33 = add i64 %31, %32
%34 = icmp ugt i64 %33, 8
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = load i32*, i32** %9
store i32 206, i32* %36
store i32 206, i32* %5
br label %46
37: ; preds = %26
%38 = load i8*, i8** %8
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %8
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%43 = call i32 @strcat(i8* %41, i8* %42)
%44 = load i32*, i32** %9
%45 = load i32, i32* %44
store i32 %45, i32* %5
br label %46
46: ; preds = %37, %35, %24
%47 = load i32, i32* %5
ret i32 %47
}

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 = add i64 %7, -8
%9 = icmp ult i64 %8, -7
%10 = icmp slt i32 %1, 0
%11 = or i1 %10, %9
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 206, i32* %3
br label %23
13: ; preds = %4
%14 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%15 = call i64 @strlen(i8* %6)
%16 = add i64 %15, %7
%17 = icmp ugt i64 %16, 8
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 206, i32* %3
br label %23
19: ; preds = %13
%20 = tail call i32 @strcpy(i8* %2, i8* %0)
%21 = call i32 @strcat(i8* %2, i8* %6)
%22 = load i32, i32* %3
br label %23
23: ; preds = %19, %18, %12
%24 = phi i32 [ 206, %12 ], [ 206, %18 ], [ %22, %19 ]
ret i32 %24
}