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

/* Variables and functions */
scalar_t__ bufcmp(scalar_t__, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int vbufcmp(struct iovec *iv1, struct iovec *iv2, int vcnt) {
  int i;
  for (i = 0; i < vcnt; iv1++, iv2++, i++) {
    if (bufcmp(iv1->iov_base, iv2->iov_base, iv1->iov_len) < 0) {
      fprintf(stderr, "Vector: %d, iv1base=%s, iv2base=%s\n", i,
              (char *)iv1->iov_base, (char *)iv2->iov_base);
      return (-1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<vbufcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c7 <vbufcmp+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
call   1030 <bufcmp@plt>
cmp    $0x0,%rax
jge    119c <vbufcmp+0x7c>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <vbufcmp+0xae>
jmp    11a1 <vbufcmp+0x81>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113a <vbufcmp+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vbufcmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1163 <vbufcmp+0x43>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r12,%rbx,1),%rdi
mov    (%r14,%rbx,1),%rsi
mov    0x8(%r12,%rbx,1),%edx
call   1030 <bufcmp@plt>
test   %rax,%rax
js     1167 <vbufcmp+0x47>
add    $0x1,%ebp
add    $0x10,%rbx
cmp    %ebp,%r15d
jne    1140 <vbufcmp+0x20>
xor    %eax,%eax
jmp    118b <vbufcmp+0x6b>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    (%r12,%rbx,1),%rcx
mov    (%r14,%rbx,1),%r8
lea    0xe81(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i64, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Vector: %d, iv1base=%s, iv2base=%s\0A\00"
define i32 @vbufcmp(%struct.iovec* %0, %struct.iovec* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.iovec*
%6 = alloca %struct.iovec*
%7 = alloca i32
%8 = alloca i32
store %struct.iovec* %0, %struct.iovec** %5
store %struct.iovec* %1, %struct.iovec** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %38, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = load %struct.iovec*, %struct.iovec** %5
%15 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load %struct.iovec*, %struct.iovec** %6
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load %struct.iovec*, %struct.iovec** %5
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i64 @bufcmp(i64 %16, i64 %19, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %13
%26 = load i32, i32* @stderr
%27 = load i32, i32* %8
%28 = load %struct.iovec*, %struct.iovec** %5
%29 = getelementptr inbounds %struct.iovec, %struct.iovec* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = load %struct.iovec*, %struct.iovec** %6
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %31, i8* %35)
store i32 -1, i32* %4
br label %46
37: ; preds = %13
br label %38
38: ; preds = %37
%39 = load %struct.iovec*, %struct.iovec** %5
%40 = getelementptr inbounds %struct.iovec, %struct.iovec* %39, i32 1
store %struct.iovec* %40, %struct.iovec** %5
%41 = load %struct.iovec*, %struct.iovec** %6
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %41, i32 1
store %struct.iovec* %42, %struct.iovec** %6
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %9
45: ; preds = %9
store i32 0, i32* %4
br label %46
46: ; preds = %45, %25
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.iovec = type { i64, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Vector: %d, iv1base=%s, iv2base=%s\0A\00"
define i32 @vbufcmp(%struct.iovec* nocapture %0, %struct.iovec* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %31
5: ; preds = %3, %26
%6 = phi i32 [ %29, %26 ], [ 0, %3 ]
%7 = phi %struct.iovec* [ %28, %26 ], [ %1, %3 ]
%8 = phi %struct.iovec* [ %27, %26 ], [ %0, %3 ]
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 0, i32 0
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 0, i32 1
%14 = load i32, i32* %13
%15 = tail call i64 @bufcmp(i64 %10, i64 %12, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %5
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 0, i32 0
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 0, i32 0
%20 = load i32, i32* @stderr
%21 = load i64, i64* %18
%22 = inttoptr i64 %21 to i8*
%23 = load i64, i64* %19
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %22, i8* %24)
br label %31
26: ; preds = %5
%27 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 1
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 1
%29 = add nuw nsw i32 %6, 1
%30 = icmp eq i32 %29, %2
br i1 %30, label %31, label %5
31: ; preds = %26, %3, %17
%32 = phi i32 [ -1, %17 ], [ 0, %3 ], [ 0, %26 ]
ret i32 %32
}