#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *shahash(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
char *db_key(char *secret, char *domain, char *id) {
  char buf[1024];
  char *hash;
  snprintf(buf, sizeof(buf), "%s", secret);
  hash = shahash(buf);
  snprintf(buf, sizeof(buf), "%s%s", hash, domain);
  hash = shahash(buf);
  snprintf(buf, sizeof(buf), "%s%s", hash, id);
  hash = shahash(buf);
  return hash;
}


x86 assembly (clang, -O0):
<db_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xeb4(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <shahash@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x400,%esi
lea    0xe7a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <shahash@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x400,%esi
lea    0xe42(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <shahash@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rcx
lea    0xec4(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <shahash@plt>
lea    0xea1(%rip),%r12
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <shahash@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <shahash@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @db_key(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = call i8* @shahash(i8* %12)
store i8* %13, i8** %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %8
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %14, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i8* @shahash(i8* %18)
store i8* %19, i8** %8
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %8
%22 = load i8*, i8** %6
%23 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = call i8* @shahash(i8* %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
ret i8* %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @db_key(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i8* @shahash(i8* %5)
%8 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %1)
%9 = call i8* @shahash(i8* %5)
%10 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %2)
%11 = call i8* @shahash(i8* %5)
ret i8* %11
}