#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 msg_buff {
  int dummy;
};

/* Variables and functions */
struct nlattr *__nla_reserve(struct msg_buff *, int, int);
scalar_t__ msg_tailroom(struct msg_buff *);
scalar_t__ nla_total_size(int);
struct nlattr *nla_reserve(struct msg_buff *msg, int attrtype, int attrlen) {
  if ((msg_tailroom(msg) < nla_total_size(attrlen)))
    return NULL;
  return __nla_reserve(msg, attrtype, attrlen);
}


x86 assembly (clang, -O0):
<nla_reserve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <msg_tailroom@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <nla_total_size@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jge    1174 <nla_reserve+0x44>
movq   $0x0,-0x8(%rbp)
jmp    1187 <nla_reserve+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <__nla_reserve@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nla_reserve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <msg_tailroom@plt>
mov    %rax,%rbx
mov    %r15d,%edi
call   1050 <nla_total_size@plt>
cmp    %rax,%rbx
jge    1162 <nla_reserve+0x32>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <__nla_reserve@plt>

LLVM IR (-O0):
%struct.nlattr = type { i32 }
%struct.msg_buff = type { i32 }
define %struct.nlattr* @nla_reserve(%struct.msg_buff* %0, i32 %1, i32 %2) {
%4 = alloca %struct.nlattr*
%5 = alloca %struct.msg_buff*
%6 = alloca i32
%7 = alloca i32
store %struct.msg_buff* %0, %struct.msg_buff** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load %struct.msg_buff*, %struct.msg_buff** %5
%9 = call i64 @msg_tailroom(%struct.msg_buff* %8)
%10 = load i32, i32* %7
%11 = call i64 @nla_total_size(i32 %10)
%12 = icmp slt i64 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %3
store %struct.nlattr* null, %struct.nlattr** %4
br label %19
14: ; preds = %3
%15 = load %struct.msg_buff*, %struct.msg_buff** %5
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = call %struct.nlattr* @__nla_reserve(%struct.msg_buff* %15, i32 %16, i32 %17)
store %struct.nlattr* %18, %struct.nlattr** %4
br label %19
19: ; preds = %14, %13
%20 = load %struct.nlattr*, %struct.nlattr** %4
ret %struct.nlattr* %20
}

LLVM IR (-O2):
%struct.nlattr = type { i32 }
%struct.msg_buff = type { i32 }
define %struct.nlattr* @nla_reserve(%struct.msg_buff* %0, i32 %1, i32 %2) {
%4 = tail call i64 @msg_tailroom(%struct.msg_buff* %0)
%5 = tail call i64 @nla_total_size(i32 %2)
%6 = icmp slt i64 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call %struct.nlattr* @__nla_reserve(%struct.msg_buff* %0, i32 %1, i32 %2)
br label %9
9: ; preds = %3, %7
%10 = phi %struct.nlattr* [ %8, %7 ], [ null, %3 ]
ret %struct.nlattr* %10
}