#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 btf_type {
  int dummy;
};
struct btf_member {
  int offset;
};
typedef int __u32;

/* Variables and functions */
int BTF_MEMBER_BIT_OFFSET(int);
int btf_kflag(struct btf_type const *);
struct btf_member *btf_members(struct btf_type const *);
__u32 btf_member_bit_offset(const struct btf_type *t, __u32 member_idx) {
  const struct btf_member *m = btf_members(t) + member_idx;
  bool kflag = btf_kflag(t);
  return kflag ? BTF_MEMBER_BIT_OFFSET(m->offset) : m->offset;
}


x86 assembly (clang, -O0):
<btf_member_bit_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <btf_members@plt>
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <btf_kflag@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1180 <btf_member_bit_offset+0x50>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <BTF_MEMBER_BIT_OFFSET@plt>
mov    %eax,-0x20(%rbp)
jmp    1189 <btf_member_bit_offset+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btf_member_bit_offset>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <btf_members@plt>
mov    %rax,%r14
movslq %ebp,%rbp
mov    %rbx,%rdi
call   1040 <btf_kflag@plt>
mov    (%r14,%rbp,4),%edi
test   %eax,%eax
je     115d <btf_member_bit_offset+0x2d>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <BTF_MEMBER_BIT_OFFSET@plt>
mov    %edi,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.btf_type = type { i32 }
%struct.btf_member = type { i32 }
define i32 @btf_member_bit_offset(%struct.btf_type* %0, i32 %1) {
%3 = alloca %struct.btf_type*
%4 = alloca i32
%5 = alloca %struct.btf_member*
%6 = alloca i32
store %struct.btf_type* %0, %struct.btf_type** %3
store i32 %1, i32* %4
%7 = load %struct.btf_type*, %struct.btf_type** %3
%8 = call %struct.btf_member* @btf_members(%struct.btf_type* %7)
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds %struct.btf_member, %struct.btf_member* %8, i64 %10
store %struct.btf_member* %11, %struct.btf_member** %5
%12 = load %struct.btf_type*, %struct.btf_type** %3
%13 = call i32 @btf_kflag(%struct.btf_type* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load %struct.btf_member*, %struct.btf_member** %5
%18 = getelementptr inbounds %struct.btf_member, %struct.btf_member* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @BTF_MEMBER_BIT_OFFSET(i32 %19)
br label %25
21: ; preds = %2
%22 = load %struct.btf_member*, %struct.btf_member** %5
%23 = getelementptr inbounds %struct.btf_member, %struct.btf_member* %22, i32 0, i32 0
%24 = load i32, i32* %23
br label %25
25: ; preds = %21, %16
%26 = phi i32 [ %20, %16 ], [ %24, %21 ]
ret i32 %26
}

LLVM IR (-O2):
%struct.btf_type = type { i32 }
%struct.btf_member = type { i32 }
define i32 @btf_member_bit_offset(%struct.btf_type* %0, i32 %1) {
%3 = tail call %struct.btf_member* @btf_members(%struct.btf_type* %0)
%4 = sext i32 %1 to i64
%5 = tail call i32 @btf_kflag(%struct.btf_type* %0)
%6 = icmp eq i32 %5, 0
%7 = getelementptr inbounds %struct.btf_member, %struct.btf_member* %3, i64 %4, i32 0
%8 = load i32, i32* %7
br i1 %6, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @BTF_MEMBER_BIT_OFFSET(i32 %8)
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ %10, %9 ], [ %8, %2 ]
ret i32 %12
}