#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 /*<<< orphan*/ kfree_skb(struct sk_buff *);
int /*<<< orphan*/ skb_cloned(struct sk_buff *);
struct sk_buff *skb_copy(struct sk_buff *, int);
struct sk_buff *skb_unshare(struct sk_buff *skb, int pri) {
  struct sk_buff *nskb;
  if (!skb_cloned(skb))
    return skb;
  nskb = skb_copy(skb, pri);
  kfree_skb(skb);
  return nskb;
}


x86 assembly (clang, -O0):
<skb_unshare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <skb_cloned@plt>
cmp    $0x0,%eax
jne    115e <skb_unshare+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117f <skb_unshare+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <skb_copy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <kfree_skb@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skb_unshare>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <skb_cloned@plt>
test   %eax,%eax
je     115b <skb_unshare+0x2b>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <skb_copy@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <kfree_skb@plt>
mov    %rbp,%rax
jmp    115e <skb_unshare+0x2e>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sk_buff = type { i32 }
define %struct.sk_buff* @skb_unshare(%struct.sk_buff* %0, i32 %1) {
%3 = tail call i32 @skb_cloned(%struct.sk_buff* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call %struct.sk_buff* @skb_copy(%struct.sk_buff* %0, i32 %1)
%7 = tail call i32 @kfree_skb(%struct.sk_buff* %0)
br label %8
8: ; preds = %2, %5
%9 = phi %struct.sk_buff* [ %6, %5 ], [ %0, %2 ]
ret %struct.sk_buff* %9
}