#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*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct rbcfg_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ get_u32(void *);
int rbcfg_find_tag(struct rbcfg_ctx *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                   void **);
int rbcfg_get_u32(struct rbcfg_ctx *ctx, uint16_t id, uint32_t *val) {
  void *tag_data;
  uint16_t tag_len;
  int err;
  err = rbcfg_find_tag(ctx, id, &tag_len, &tag_data);
  if (err)
    return err;
  *val = get_u32(tag_data);
  return 0;
}


x86 assembly (clang, -O0):
<rbcfg_get_u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <rbcfg_find_tag@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     115f <rbcfg_get_u32+0x3f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <rbcfg_get_u32+0x57>
mov    -0x28(%rbp),%rdi
call   1030 <get_u32@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rbcfg_get_u32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
lea    0x14(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1040 <rbcfg_find_tag@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    114a <rbcfg_get_u32+0x2a>
mov    0x8(%rsp),%rdi
call   1030 <get_u32@plt>
mov    %eax,(%rbx)
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rbcfg_ctx = type { i32 }
define i32 @rbcfg_get_u32(%struct.rbcfg_ctx* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.rbcfg_ctx*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store %struct.rbcfg_ctx* %0, %struct.rbcfg_ctx** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load %struct.rbcfg_ctx*, %struct.rbcfg_ctx** %5
%12 = load i32, i32* %6
%13 = call i32 @rbcfg_find_tag(%struct.rbcfg_ctx* %11, i32 %12, i32* %9, i8** %8)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %10
store i32 %17, i32* %4
br label %22
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = call i32 @get_u32(i8* %19)
%21 = load i32*, i32** %7
store i32 %20, i32* %21
store i32 0, i32* %4
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.rbcfg_ctx = type { i32 }
define i32 @rbcfg_get_u32(%struct.rbcfg_ctx* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i8** %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i32 @rbcfg_find_tag(%struct.rbcfg_ctx* %0, i32 %1, i32* %5, i8** %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @get_u32(i8* %11)
store i32 %12, i32* %2
br label %13
13: ; preds = %3, %10
ret i32 %8
}