#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 ubsan_value_handle {
  int dummy;
};
struct ubsan_type_descriptor {
  int dummy;
};
typedef int /*<<< orphan*/ intmax_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *,
                           struct ubsan_type_descriptor const *);
int /*<<< orphan*/ load_int(struct ubsan_type_descriptor const *,
                            struct ubsan_value_handle const *);
int /*<<< orphan*/ stderr;
scalar_t__ value_is_inline(struct ubsan_type_descriptor const *);
int /*<<< orphan*/ value_is_signed(struct ubsan_type_descriptor const *);
intmax_t value_int(const struct ubsan_type_descriptor *desc,
                   const struct ubsan_value_handle *vh) {
  assert(value_is_signed(desc));
  if (value_is_inline(desc)) {
    return (intmax_t)(uintptr_t)vh;
  } else {
    fprintf(stderr, "loading non-inline int: %p\n", desc);
    return load_int(desc, vh);
  }
}


x86 assembly (clang, -O0):
<value_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <value_is_signed@plt>
mov    %eax,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <value_is_inline@plt>
cmp    $0x0,%rax
je     118f <value_int+0x3f>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11b8 <value_int+0x68>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <load_int@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<value_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <value_is_signed@plt>
mov    %eax,%edi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <value_is_inline@plt>
test   %rax,%rax
je     117e <value_int+0x2e>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <load_int@plt>

LLVM IR (-O0):
%struct.ubsan_type_descriptor = type { i32 }
%struct.ubsan_value_handle = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"loading non-inline int: %p\0A\00"
define i32 @value_int(%struct.ubsan_type_descriptor* %0, %struct.ubsan_value_handle* %1) {
%3 = alloca i32
%4 = alloca %struct.ubsan_type_descriptor*
%5 = alloca %struct.ubsan_value_handle*
store %struct.ubsan_type_descriptor* %0, %struct.ubsan_type_descriptor** %4
store %struct.ubsan_value_handle* %1, %struct.ubsan_value_handle** %5
%6 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%7 = call i32 @value_is_signed(%struct.ubsan_type_descriptor* %6)
%8 = call i32 @assert(i32 %7)
%9 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%10 = call i64 @value_is_inline(%struct.ubsan_type_descriptor* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load %struct.ubsan_value_handle*, %struct.ubsan_value_handle** %5
%14 = ptrtoint %struct.ubsan_value_handle* %13 to i64
%15 = trunc i64 %14 to i32
store i32 %15, i32* %3
br label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %struct.ubsan_type_descriptor* %18)
%20 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%21 = load %struct.ubsan_value_handle*, %struct.ubsan_value_handle** %5
%22 = call i32 @load_int(%struct.ubsan_type_descriptor* %20, %struct.ubsan_value_handle* %21)
store i32 %22, i32* %3
br label %23
23: ; preds = %16, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.ubsan_type_descriptor = type { i32 }
%struct.ubsan_value_handle = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"loading non-inline int: %p\0A\00"
define i32 @value_int(%struct.ubsan_type_descriptor* %0, %struct.ubsan_value_handle* %1) {
%3 = tail call i32 @value_is_signed(%struct.ubsan_type_descriptor* %0)
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 @value_is_inline(%struct.ubsan_type_descriptor* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = ptrtoint %struct.ubsan_value_handle* %1 to i64
%9 = trunc i64 %8 to i32
br label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %struct.ubsan_type_descriptor* %0)
%13 = tail call i32 @load_int(%struct.ubsan_type_descriptor* %0, %struct.ubsan_value_handle* %1)
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ %9, %7 ], [ %13, %10 ]
ret i32 %15
}