#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 void inthash;
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
void *ih_getval(void *, int /*<<< orphan*/);
int /*<<< orphan*/ ih_setval(void *, int /*<<< orphan*/, void *);
void *new_inthash();
void ih_setval2(struct inthash *ih, int64_t key1, int64_t key2, void *data) {
  struct inthash *ih2 = ih_getval(ih, key1);
  if (!ih2) {
    ih2 = new_inthash();
    ih_setval(ih, key1, ih2);
  }
  ih_setval(ih2, key2, data);
}


x86 assembly (clang, -O0):
<ih_setval2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <ih_getval@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <ih_setval2+0x4c>
mov    $0x0,%al
call   1050 <new_inthash@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <ih_setval@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <ih_setval@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ih_setval2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
call   1030 <ih_getval@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1169 <ih_setval2+0x39>
xor    %eax,%eax
call   1050 <new_inthash@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %rax,%rdx
call   1040 <ih_setval@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ih_setval@plt>

LLVM IR (-O0):
%struct.inthash = type opaque
define void @ih_setval2(%struct.inthash* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca %struct.inthash*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.inthash*
store %struct.inthash* %0, %struct.inthash** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load %struct.inthash*, %struct.inthash** %5
%11 = bitcast %struct.inthash* %10 to i8*
%12 = load i32, i32* %6
%13 = call i8* @ih_getval(i8* %11, i32 %12)
%14 = bitcast i8* %13 to %struct.inthash*
store %struct.inthash* %14, %struct.inthash** %9
%15 = load %struct.inthash*, %struct.inthash** %9
%16 = icmp ne %struct.inthash* %15, null
br i1 %16, label %26, label %17
17: ; preds = %4
%18 = call i8* (...) @new_inthash()
%19 = bitcast i8* %18 to %struct.inthash*
store %struct.inthash* %19, %struct.inthash** %9
%20 = load %struct.inthash*, %struct.inthash** %5
%21 = bitcast %struct.inthash* %20 to i8*
%22 = load i32, i32* %6
%23 = load %struct.inthash*, %struct.inthash** %9
%24 = bitcast %struct.inthash* %23 to i8*
%25 = call i32 @ih_setval(i8* %21, i32 %22, i8* %24)
br label %26
26: ; preds = %17, %4
%27 = load %struct.inthash*, %struct.inthash** %9
%28 = bitcast %struct.inthash* %27 to i8*
%29 = load i32, i32* %7
%30 = load i8*, i8** %8
%31 = call i32 @ih_setval(i8* %28, i32 %29, i8* %30)
ret void
}

LLVM IR (-O2):
%struct.inthash = type opaque
define void @ih_setval2(%struct.inthash* %0, i32 %1, i32 %2, i8* %3) {
%5 = bitcast %struct.inthash* %0 to i8*
%6 = tail call i8* @ih_getval(i8* %5, i32 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i8* (...) @new_inthash()
%10 = tail call i32 @ih_setval(i8* %5, i32 %1, i8* %9)
br label %11
11: ; preds = %8, %4
%12 = phi i8* [ %6, %4 ], [ %9, %8 ]
%13 = tail call i32 @ih_setval(i8* %12, i32 %2, i8* %3)
ret void
}