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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int count_blacklists(struct sock_filter *, int);
int optimize_blacklists(struct sock_filter *, int);
int optimize(struct sock_filter *filter, int entries) {
  assert(filter);
  assert(entries);
  int cnt = count_blacklists(filter, entries);
  if (cnt > 4)
    entries = optimize_blacklists(filter, entries);
  return entries;
}


x86 assembly (clang, -O0):
<optimize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <count_blacklists@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jle    117a <optimize+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <optimize_blacklists@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optimize>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <assert@plt>
mov    %ebx,%edi
call   1030 <assert@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <count_blacklists@plt>
cmp    $0x5,%eax
jl     1165 <optimize+0x35>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <optimize_blacklists@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sock_filter = type { i32 }
define i32 @optimize(%struct.sock_filter* %0, i32 %1) {
%3 = alloca %struct.sock_filter*
%4 = alloca i32
%5 = alloca i32
store %struct.sock_filter* %0, %struct.sock_filter** %3
store i32 %1, i32* %4
%6 = load %struct.sock_filter*, %struct.sock_filter** %3
%7 = ptrtoint %struct.sock_filter* %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %4
%10 = call i32 @assert(i32 %9)
%11 = load %struct.sock_filter*, %struct.sock_filter** %3
%12 = load i32, i32* %4
%13 = call i32 @count_blacklists(%struct.sock_filter* %11, i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 4
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load %struct.sock_filter*, %struct.sock_filter** %3
%18 = load i32, i32* %4
%19 = call i32 @optimize_blacklists(%struct.sock_filter* %17, i32 %18)
store i32 %19, i32* %4
br label %20
20: ; preds = %16, %2
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.sock_filter = type { i32 }
define i32 @optimize(%struct.sock_filter* %0, i32 %1) {
%3 = ptrtoint %struct.sock_filter* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @assert(i32 %1)
%7 = tail call i32 @count_blacklists(%struct.sock_filter* %0, i32 %1)
%8 = icmp sgt i32 %7, 4
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @optimize_blacklists(%struct.sock_filter* %0, i32 %1)
br label %11
11: ; preds = %9, %2
%12 = phi i32 [ %10, %9 ], [ %1, %2 ]
ret i32 %12
}