#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 pcap_packet {
  int dummy;
};
struct packet_list {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free_pcap_packet(struct pcap_packet **, int);
struct pcap_packet *get_packets(int, struct packet_list **);
int remove_first_X_packets(int nb_packets, struct packet_list **list,
                           int use_mutex) {
  struct pcap_packet *packets;
  if (list == NULL || *list == NULL || nb_packets < 0) {
    return EXIT_FAILURE;
  }
  if (nb_packets == 0) {
    return EXIT_SUCCESS;
  }
  packets = get_packets(nb_packets, list);
  free_pcap_packet(&packets, 1);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<remove_first_X_packets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <remove_first_X_packets+0x35>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1155 <remove_first_X_packets+0x35>
cmpl   $0x0,-0x8(%rbp)
jge    1166 <remove_first_X_packets+0x46>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <remove_first_X_packets+0x8b>
cmpl   $0x0,-0x8(%rbp)
jne    1181 <remove_first_X_packets+0x61>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <remove_first_X_packets+0x8b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <get_packets@plt>
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <free_pcap_packet@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_first_X_packets>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eb4(%rip),%rbx
test   %rsi,%rsi
je     115f <remove_first_X_packets+0x3f>
test   %edi,%edi
js     115f <remove_first_X_packets+0x3f>
cmpq   $0x0,(%rsi)
je     115f <remove_first_X_packets+0x3f>
mov    0x2e96(%rip),%rbx
test   %edi,%edi
je     115f <remove_first_X_packets+0x3f>
call   1030 <get_packets@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1040 <free_pcap_packet@plt>
mov    (%rbx),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.packet_list = type { i32 }
%struct.pcap_packet = type { i32 }
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @remove_first_X_packets(i32 %0, %struct.packet_list** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.packet_list**
%7 = alloca i32
%8 = alloca %struct.pcap_packet*
store i32 %0, i32* %5
store %struct.packet_list** %1, %struct.packet_list*** %6
store i32 %2, i32* %7
%9 = load %struct.packet_list**, %struct.packet_list*** %6
%10 = icmp eq %struct.packet_list** %9, null
br i1 %10, label %18, label %11
11: ; preds = %3
%12 = load %struct.packet_list**, %struct.packet_list*** %6
%13 = load %struct.packet_list*, %struct.packet_list** %12
%14 = icmp eq %struct.packet_list* %13, null
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %11, %3
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %4
br label %31
20: ; preds = %15
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %4
br label %31
25: ; preds = %20
%26 = load i32, i32* %5
%27 = load %struct.packet_list**, %struct.packet_list*** %6
%28 = call %struct.pcap_packet* @get_packets(i32 %26, %struct.packet_list** %27)
store %struct.pcap_packet* %28, %struct.pcap_packet** %8
%29 = call i32 @free_pcap_packet(%struct.pcap_packet** %8, i32 1)
%30 = load i32, i32* @EXIT_SUCCESS
store i32 %30, i32* %4
br label %31
31: ; preds = %25, %23, %18
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.packet_list = type { i32 }
%struct.pcap_packet = type { i32 }
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @remove_first_X_packets(i32 %0, %struct.packet_list** %1, i32 %2) {
%4 = alloca %struct.pcap_packet*
%5 = bitcast %struct.pcap_packet** %4 to i8*
%6 = icmp eq %struct.packet_list** %1, null
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = load %struct.packet_list*, %struct.packet_list** %1
%9 = icmp eq %struct.packet_list* %8, null
%10 = icmp slt i32 %0, 0
%11 = or i1 %10, %9
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = icmp eq i32 %0, 0
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = tail call %struct.pcap_packet* @get_packets(i32 %0, %struct.packet_list** %1)
store %struct.pcap_packet* %15, %struct.pcap_packet** %4
%16 = call i32 @free_pcap_packet(%struct.pcap_packet** %4, i32 1)
br label %17
17: ; preds = %12, %3, %7, %14
%18 = phi i32* [ @EXIT_SUCCESS, %14 ], [ @EXIT_FAILURE, %7 ], [ @EXIT_FAILURE, %3 ], [ @EXIT_SUCCESS, %12 ]
%19 = load i32, i32* %18
ret i32 %19
}