#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 */
unsigned long alloc_key_disk(int);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ save_data(unsigned long, char *, int);
int strlen(char *);
unsigned long save_name(char *key) {
  int len = strlen(key);
  unsigned long keys_id = alloc_key_disk(len);
  if (keys_id != -1) {
    save_data(keys_id, key, len);
    printf("return key_id is 0x%llx\r\n", keys_id);
    return keys_id;
  }
  return -1;
}


x86 assembly (clang, -O0):
<save_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <alloc_key_disk@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     119c <save_name+0x5c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <save_data@plt>
mov    -0x20(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <save_name+0x64>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <alloc_key_disk@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
je     117a <save_name+0x3a>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <save_data@plt>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"return key_id is 0x%llx\0D\0A\00"
define i64 @save_name(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i64 @alloc_key_disk(i32 %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp ne i64 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i64, i64* %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = call i32 @save_data(i64 %13, i8* %14, i32 %15)
%17 = load i64, i64* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i64, i64* %5
store i64 %19, i64* %2
br label %21
20: ; preds = %1
store i64 -1, i64* %2
br label %21
21: ; preds = %20, %12
%22 = load i64, i64* %2
ret i64 %22
}

LLVM IR (-O2):
@.str = [26 x i8] c"return key_id is 0x%llx\0D\0A\00"
define i64 @save_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @alloc_key_disk(i32 %2)
%4 = icmp eq i64 %3, -1
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i32 @save_data(i64 %3, i8* %0, i32 %2)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %3)
br label %8
8: ; preds = %1, %5
ret i64 %3
}