#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 nlattr {
  int dummy;
};
struct libbpf_nla_req {
  int dummy;
};

/* Variables and functions */
int NLA_F_NESTED;
scalar_t__ nlattr_add(struct libbpf_nla_req *, int, int /*<<< orphan*/ *,
                      int /*<<< orphan*/);
struct nlattr *req_tail(struct libbpf_nla_req *);
struct nlattr *nlattr_begin_nested(struct libbpf_nla_req *req, int type) {
  struct nlattr *tail;
  tail = req_tail(req);
  if (nlattr_add(req, type | NLA_F_NESTED, NULL, 0))
    return NULL;
  return tail;
}


x86 assembly (clang, -O0):
<nlattr_begin_nested>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <req_tail@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <nlattr_add@plt>
cmp    $0x0,%rax
je     116e <nlattr_begin_nested+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1176 <nlattr_begin_nested+0x56>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nlattr_begin_nested>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <req_tail@plt>
mov    %rax,%r15
mov    0x2ea4(%rip),%rax
or     (%rax),%ebx
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <nlattr_add@plt>
test   %rax,%rax
cmovne %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.nlattr = type { i32 }
%struct.libbpf_nla_req = type { i32 }
@NLA_F_NESTED = global i32 0
define %struct.nlattr* @nlattr_begin_nested(%struct.libbpf_nla_req* %0, i32 %1) {
%3 = alloca %struct.nlattr*
%4 = alloca %struct.libbpf_nla_req*
%5 = alloca i32
%6 = alloca %struct.nlattr*
store %struct.libbpf_nla_req* %0, %struct.libbpf_nla_req** %4
store i32 %1, i32* %5
%7 = load %struct.libbpf_nla_req*, %struct.libbpf_nla_req** %4
%8 = call %struct.nlattr* @req_tail(%struct.libbpf_nla_req* %7)
store %struct.nlattr* %8, %struct.nlattr** %6
%9 = load %struct.libbpf_nla_req*, %struct.libbpf_nla_req** %4
%10 = load i32, i32* %5
%11 = load i32, i32* @NLA_F_NESTED
%12 = or i32 %10, %11
%13 = call i64 @nlattr_add(%struct.libbpf_nla_req* %9, i32 %12, i32* null, i32 0)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store %struct.nlattr* null, %struct.nlattr** %3
br label %18
16: ; preds = %2
%17 = load %struct.nlattr*, %struct.nlattr** %6
store %struct.nlattr* %17, %struct.nlattr** %3
br label %18
18: ; preds = %16, %15
%19 = load %struct.nlattr*, %struct.nlattr** %3
ret %struct.nlattr* %19
}

LLVM IR (-O2):
%struct.nlattr = type { i32 }
%struct.libbpf_nla_req = type { i32 }
@NLA_F_NESTED = global i32 0
define %struct.nlattr* @nlattr_begin_nested(%struct.libbpf_nla_req* %0, i32 %1) {
%3 = tail call %struct.nlattr* @req_tail(%struct.libbpf_nla_req* %0)
%4 = load i32, i32* @NLA_F_NESTED
%5 = or i32 %4, %1
%6 = tail call i64 @nlattr_add(%struct.libbpf_nla_req* %0, i32 %5, i32* null, i32 0)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, %struct.nlattr* %3, %struct.nlattr* null
ret %struct.nlattr* %8
}