#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 */
struct ltable_value {
  int dummy;
};
struct ltable_key {
  int dummy;
};
struct ltable {
  int dummy;
};

/* Variables and functions */
struct ltable_value *_get(struct ltable *, struct ltable_key const *);
void *_gud(struct ltable_value *);
struct ltable_value *_set(struct ltable *, struct ltable_key const *);
void *ltable_set(struct ltable *t, const struct ltable_key *key) {
  struct ltable_value *val = _get(t, key);
  if (!val)
    val = _set(t, key);
  return _gud(val);
}


x86 assembly (clang, -O0):
<ltable_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <_get@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <ltable_set+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <_set@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <_gud@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltable_set>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <_get@plt>
test   %rax,%rax
jne    114f <ltable_set+0x1f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <_set@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <_gud@plt>

LLVM IR (-O0):
%struct.ltable = type { i32 }
%struct.ltable_key = type { i32 }
%struct.ltable_value = type { i32 }
define i8* @ltable_set(%struct.ltable* %0, %struct.ltable_key* %1) {
%3 = alloca %struct.ltable*
%4 = alloca %struct.ltable_key*
%5 = alloca %struct.ltable_value*
store %struct.ltable* %0, %struct.ltable** %3
store %struct.ltable_key* %1, %struct.ltable_key** %4
%6 = load %struct.ltable*, %struct.ltable** %3
%7 = load %struct.ltable_key*, %struct.ltable_key** %4
%8 = call %struct.ltable_value* @_get(%struct.ltable* %6, %struct.ltable_key* %7)
store %struct.ltable_value* %8, %struct.ltable_value** %5
%9 = load %struct.ltable_value*, %struct.ltable_value** %5
%10 = icmp ne %struct.ltable_value* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load %struct.ltable*, %struct.ltable** %3
%13 = load %struct.ltable_key*, %struct.ltable_key** %4
%14 = call %struct.ltable_value* @_set(%struct.ltable* %12, %struct.ltable_key* %13)
store %struct.ltable_value* %14, %struct.ltable_value** %5
br label %15
15: ; preds = %11, %2
%16 = load %struct.ltable_value*, %struct.ltable_value** %5
%17 = call i8* @_gud(%struct.ltable_value* %16)
ret i8* %17
}

LLVM IR (-O2):
%struct.ltable = type { i32 }
%struct.ltable_key = type { i32 }
%struct.ltable_value = type { i32 }
define i8* @ltable_set(%struct.ltable* %0, %struct.ltable_key* %1) {
%3 = tail call %struct.ltable_value* @_get(%struct.ltable* %0, %struct.ltable_key* %1)
%4 = icmp eq %struct.ltable_value* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call %struct.ltable_value* @_set(%struct.ltable* %0, %struct.ltable_key* %1)
br label %7
7: ; preds = %5, %2
%8 = phi %struct.ltable_value* [ %3, %2 ], [ %6, %5 ]
%9 = tail call i8* @_gud(%struct.ltable_value* %8)
ret i8* %9
}