#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 *);
struct sk_buff *skb_clone(struct sk_buff *, int);
scalar_t__ skb_shared(struct sk_buff *);
struct sk_buff *skb_share_check(struct sk_buff *skb, int pri) {
  if (skb_shared(skb)) {
    struct sk_buff *nskb;
    nskb = skb_clone(skb, pri);
    kfree_skb(skb);
    return nskb;
  }
  return skb;
}


x86 assembly (clang, -O0):
<skb_share_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <skb_shared@plt>
cmp    $0x0,%rax
je     1178 <skb_share_check+0x48>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <skb_clone@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <kfree_skb@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <skb_share_check+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skb_share_check>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <skb_shared@plt>
test   %rax,%rax
je     115c <skb_share_check+0x2c>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <skb_clone@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <kfree_skb@plt>
mov    %rbp,%rax
jmp    115f <skb_share_check+0x2f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sk_buff = type { i32 }
define %struct.sk_buff* @skb_share_check(%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 i64 @skb_shared(%struct.sk_buff* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load %struct.sk_buff*, %struct.sk_buff** %4
%12 = load i32, i32* %5
%13 = call %struct.sk_buff* @skb_clone(%struct.sk_buff* %11, i32 %12)
store %struct.sk_buff* %13, %struct.sk_buff** %6
%14 = load %struct.sk_buff*, %struct.sk_buff** %4
%15 = call i32 @kfree_skb(%struct.sk_buff* %14)
%16 = load %struct.sk_buff*, %struct.sk_buff** %6
store %struct.sk_buff* %16, %struct.sk_buff** %3
br label %19
17: ; preds = %2
%18 = load %struct.sk_buff*, %struct.sk_buff** %4
store %struct.sk_buff* %18, %struct.sk_buff** %3
br label %19
19: ; preds = %17, %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_share_check(%struct.sk_buff* %0, i32 %1) {
%3 = tail call i64 @skb_shared(%struct.sk_buff* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call %struct.sk_buff* @skb_clone(%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
}