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

/* Variables and functions */
int pskb_expand_head(struct sk_buff *, int, int /*<<< orphan*/, int);
scalar_t__ skb_cloned(struct sk_buff *);
unsigned int skb_headroom(struct sk_buff *);
int skb_cow(struct sk_buff *skb, unsigned int headroom) {
  int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
  if (delta < 0)
    delta = 0;
  if (delta || skb_cloned(skb))
    return pskb_expand_head(skb, (delta + 15) & ~15, 0, (0x20));
  return 0;
}


x86 assembly (clang, -O0):
<skb_cow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jbe    1154 <skb_cow+0x24>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <skb_cow+0x31>
mov    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <skb_cow+0x31>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <skb_headroom@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    118b <skb_cow+0x5b>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a8 <skb_cow+0x78>
mov    -0x10(%rbp),%rdi
call   1030 <skb_cloned@plt>
cmp    $0x0,%rax
je     11c9 <skb_cow+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0xf,%esi
and    $0xfffffff0,%esi
xor    %edx,%edx
mov    $0x20,%ecx
call   1040 <pskb_expand_head@plt>
mov    %eax,-0x4(%rbp)
jmp    11d0 <skb_cow+0xa0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skb_cow>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x11,%esi
mov    $0x10,%ebx
cmovae %esi,%ebx
call   1050 <skb_headroom@plt>
sub    %eax,%ebx
test   %ebx,%ebx
jg     115a <skb_cow+0x2a>
mov    %r14,%rdi
call   1030 <skb_cloned@plt>
test   %rax,%rax
je     117d <skb_cow+0x4d>
lea    0xf(%rbx),%esi
and    $0xfffffff0,%esi
xor    %eax,%eax
test   %ebx,%ebx
cmovle %eax,%esi
mov    %r14,%rdi
xor    %edx,%edx
mov    $0x20,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <pskb_expand_head@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sk_buff = type { i32 }
define i32 @skb_cow(%struct.sk_buff* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sk_buff*
%5 = alloca i32
%6 = alloca i32
store %struct.sk_buff* %0, %struct.sk_buff** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ugt i32 %7, 16
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i32, i32* %5
br label %12
11: ; preds = %2
br label %12
12: ; preds = %11, %9
%13 = phi i32 [ %10, %9 ], [ 16, %11 ]
%14 = load %struct.sk_buff*, %struct.sk_buff** %4
%15 = call i32 @skb_headroom(%struct.sk_buff* %14)
%16 = sub i32 %13, %15
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 0, i32* %6
br label %20
20: ; preds = %19, %12
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load %struct.sk_buff*, %struct.sk_buff** %4
%25 = call i64 @skb_cloned(%struct.sk_buff* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23, %20
%28 = load %struct.sk_buff*, %struct.sk_buff** %4
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 15
%31 = and i32 %30, -16
%32 = call i32 @pskb_expand_head(%struct.sk_buff* %28, i32 %31, i32 0, i32 32)
store i32 %32, i32* %3
br label %34
33: ; preds = %23
store i32 0, i32* %3
br label %34
34: ; preds = %33, %27
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.sk_buff = type { i32 }
define i32 @skb_cow(%struct.sk_buff* %0, i32 %1) {
%3 = icmp ugt i32 %1, 16
%4 = select i1 %3, i32 %1, i32 16
%5 = tail call i32 @skb_headroom(%struct.sk_buff* %0)
%6 = sub i32 %4, %5
%7 = icmp sgt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i64 @skb_cloned(%struct.sk_buff* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %8, %2
%12 = add nsw i32 %6, 15
%13 = and i32 %12, -16
%14 = select i1 %7, i32 %13, i32 0
%15 = tail call i32 @pskb_expand_head(%struct.sk_buff* %0, i32 %14, i32 0, i32 32)
br label %16
16: ; preds = %8, %11
%17 = phi i32 [ %15, %11 ], [ 0, %8 ]
ret i32 %17
}