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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
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 *);
uintmax_t value_uint(const struct ubsan_type_descriptor *desc,
                     const struct ubsan_value_handle *vh) {
  assert(!value_is_signed(desc));
  if (value_is_inline(desc)) {
    return (uintmax_t)(uintptr_t)vh;
  } else {
    fprintf(stderr, "loading non-inline uint: %p\n", desc);
    return load_int(desc, vh);
  }
}


x86 assembly (clang, -O0):
<value_uint>:
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>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <value_is_inline@plt>
cmp    $0x0,%rax
je     119a <value_uint+0x4a>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11c3 <value_uint+0x73>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe52(%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_uint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <value_is_signed@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <value_is_inline@plt>
test   %rax,%rax
je     1184 <value_uint+0x34>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%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 = [29 x i8] c"loading non-inline uint: %p\0A\00"
define i32 @value_uint(%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 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%13 = call i64 @value_is_inline(%struct.ubsan_type_descriptor* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load %struct.ubsan_value_handle*, %struct.ubsan_value_handle** %5
%17 = ptrtoint %struct.ubsan_value_handle* %16 to i64
%18 = trunc i64 %17 to i32
store i32 %18, i32* %3
br label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %struct.ubsan_type_descriptor* %21)
%23 = load %struct.ubsan_type_descriptor*, %struct.ubsan_type_descriptor** %4
%24 = load %struct.ubsan_value_handle*, %struct.ubsan_value_handle** %5
%25 = call i32 @load_int(%struct.ubsan_type_descriptor* %23, %struct.ubsan_value_handle* %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %19, %15
%27 = load i32, i32* %3
ret i32 %27
}

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