#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 scalar_t__ uint32_t;
struct hashtable {
  int dummy;
};

/* Variables and functions */
scalar_t__ hashtable_get_val(struct hashtable *, scalar_t__);
scalar_t__ hashtable_lookup(struct hashtable *, char const *,
                            int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
const char *hashtable_lookup_str(struct hashtable *ht, const char *key,
                                 const char *default_val) {
  uint32_t ofs = hashtable_lookup(ht, key, strlen(key));
  return (ofs ? (const char *)hashtable_get_val(ht, ofs) : default_val);
}


x86 assembly (clang, -O0):
<hashtable_lookup_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <hashtable_lookup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1191 <hashtable_lookup_str+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <hashtable_get_val@plt>
mov    %rax,-0x38(%rbp)
jmp    1199 <hashtable_lookup_str+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashtable_lookup_str>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <hashtable_lookup@plt>
test   %rax,%rax
je     1166 <hashtable_lookup_str+0x36>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <hashtable_get_val@plt>
mov    %rax,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hashtable = type { i32 }
define i8* @hashtable_lookup_str(%struct.hashtable* %0, i8* %1, i8* %2) {
%4 = alloca %struct.hashtable*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store %struct.hashtable* %0, %struct.hashtable** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load %struct.hashtable*, %struct.hashtable** %4
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = call i64 @hashtable_lookup(%struct.hashtable* %8, i8* %9, i32 %11)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load %struct.hashtable*, %struct.hashtable** %4
%17 = load i64, i64* %7
%18 = call i64 @hashtable_get_val(%struct.hashtable* %16, i64 %17)
%19 = inttoptr i64 %18 to i8*
br label %22
20: ; preds = %3
%21 = load i8*, i8** %6
br label %22
22: ; preds = %20, %15
%23 = phi i8* [ %19, %15 ], [ %21, %20 ]
ret i8* %23
}

LLVM IR (-O2):
%struct.hashtable = type { i32 }
define i8* @hashtable_lookup_str(%struct.hashtable* %0, i8* %1, i8* readnone %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i64 @hashtable_lookup(%struct.hashtable* %0, i8* %1, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i64 @hashtable_get_val(%struct.hashtable* %0, i64 %5)
%9 = inttoptr i64 %8 to i8*
br label %10
10: ; preds = %3, %7
%11 = phi i8* [ %9, %7 ], [ %2, %3 ]
ret i8* %11
}