#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 iovec {
  int /*<<< orphan*/ iov_len;
  int /*<<< orphan*/ iov_base;
};

/* Variables and functions */
int /*<<< orphan*/ munmap(int /*<<< orphan*/, int /*<<< orphan*/);
void iovec_free(int *iovec_entries, struct iovec **iovector) {
  int i;
  for (i = 0; i < *iovec_entries; ++i)
    munmap(((*iovector)[i]).iov_base, ((*iovector)[i]).iov_len);
  *iovec_entries = 0;
}


x86 assembly (clang, -O0):
<iovec_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    1166 <iovec_free+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%esi
call   1030 <munmap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <iovec_free+0x17>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iovec_free>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
cmpl   $0x0,(%rdi)
jle    114b <iovec_free+0x3b>
mov    %rsi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%rax
mov    (%rax,%rbx,8),%esi
mov    0x4(%rax,%rbx,8),%edi
call   1030 <munmap@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     1130 <iovec_free+0x20>
movl   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iovec = type { i32, i32 }
define void @iovec_free(i32* %0, %struct.iovec** %1) {
%3 = alloca i32*
%4 = alloca %struct.iovec**
%5 = alloca i32
store i32* %0, i32** %3
store %struct.iovec** %1, %struct.iovec*** %4
store i32 0, i32* %5
br label %6
6: ; preds = %27, %2
%7 = load i32, i32* %5
%8 = load i32*, i32** %3
%9 = load i32, i32* %8
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %30
11: ; preds = %6
%12 = load %struct.iovec**, %struct.iovec*** %4
%13 = load %struct.iovec*, %struct.iovec** %12
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i64 %15
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load %struct.iovec**, %struct.iovec*** %4
%20 = load %struct.iovec*, %struct.iovec** %19
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i64 %22
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @munmap(i32 %18, i32 %25)
br label %27
27: ; preds = %11
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %6
30: ; preds = %6
%31 = load i32*, i32** %3
store i32 0, i32* %31
ret void
}

LLVM IR (-O2):
%struct.iovec = type { i32, i32 }
define void @iovec_free(i32* nocapture %0, %struct.iovec** nocapture %1) {
%3 = load i32, i32* %0
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2, %5
%6 = phi i64 [ %13, %5 ], [ 0, %2 ]
%7 = load %struct.iovec*, %struct.iovec** %1
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 %6, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 %6, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @munmap(i32 %9, i32 %11)
%13 = add nuw nsw i64 %6, 1
%14 = load i32, i32* %0
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %5, label %17
17: ; preds = %5, %2
store i32 0, i32* %0
ret void
}