#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 const *);
size_t strlen(char const *);
int ffnkey(int value, const char *keyroot, char *keyname, int *status) {
  size_t rootlen;
  keyname[0] = '\0';
  rootlen = strlen(keyroot);
  if (rootlen == 0 || rootlen > 7 || value < 0)
    return (*status = 206);
  snprintf(keyname, 71, "%d", value);
  if (rootlen + strlen(keyname) > 8)
    return (*status = 206);
  strcat(keyname, keyroot);
  return (*status);
}


x86 assembly (clang, -O0):
<ffnkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     117b <ffnkey+0x4b>
cmpq   $0x7,-0x28(%rbp)
ja     117b <ffnkey+0x4b>
cmpl   $0x0,-0x8(%rbp)
jge    1191 <ffnkey+0x61>
mov    -0x20(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    11fa <ffnkey+0xca>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x47,%esi
lea    0xe5c(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
cmp    $0x8,%rax
jbe    11e4 <ffnkey+0xb4>
mov    -0x20(%rbp),%rax
movl   $0xce,(%rax)
movl   $0xce,-0x4(%rbp)
jmp    11fa <ffnkey+0xca>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffnkey>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%ebp
movb   $0x0,(%rdx)
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %ebp,%ebp
js     1186 <ffnkey+0x56>
mov    %rax,%r12
add    $0xfffffffffffffff8,%rax
cmp    $0xfffffffffffffff8,%rax
jbe    1186 <ffnkey+0x56>
lea    0xe9a(%rip),%rdx
mov    %rbx,%rdi
mov    $0x47,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %r12,%rax
cmp    $0x9,%rax
jb     1194 <ffnkey+0x64>
movl   $0xce,(%r14)
mov    $0xce,%eax
jmp    11a2 <ffnkey+0x72>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    (%r14),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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