#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 iov_len;
  scalar_t__ iov_base;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int compare_buffers(struct iovec *iov1, struct iovec *iov2, int count) {
  int i, j;
  for (i = 0; i < count; i++) {
    if (iov1[i].iov_len != iov2[i].iov_len) {
      fprintf(stderr, "length mismatch\n");
      break;
    }
    for (j = 0; j < iov1[i].iov_len; j++) {
      if (*((char *)iov1[i].iov_base + j) != *((char *)iov2[i].iov_base + j)) {
        fprintf(stderr, "index %d, char %d in streamsize %ld\n", i, j,
                (long)iov1[i].iov_len);
        break;
      }
    }
    if (j != iov1[i].iov_len)
      break;
  }
  if (i != count) {
    fprintf(stderr, "Tests failed\n");
    return -1;
  } else {
    printf("Tests passed!\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<compare_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    1262 <compare_buffers+0x142>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
cmp    (%rcx),%eax
je     118a <compare_buffers+0x6a>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1262 <compare_buffers+0x142>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
cmp    (%rcx),%eax
jge    1230 <compare_buffers+0x110>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
mov    0x8(%rcx),%rcx
movslq -0x24(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     121d <compare_buffers+0xfd>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rsi
shl    $0x4,%rsi
add    %rsi,%rax
movslq (%rax),%r8
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1230 <compare_buffers+0x110>
jmp    1222 <compare_buffers+0x102>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1191 <compare_buffers+0x71>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
cmp    (%rcx),%eax
je     124f <compare_buffers+0x12f>
jmp    1262 <compare_buffers+0x142>
jmp    1254 <compare_buffers+0x134>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113a <compare_buffers+0x1a>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1291 <compare_buffers+0x171>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <compare_buffers+0x184>
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_buffers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11e8 <compare_buffers+0xc8>
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,0x4(%rsp)
mov    %edx,%esi
xor    %r12d,%r12d
jmp    1160 <compare_buffers+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
cmp    %eax,%ebp
je     11d9 <compare_buffers+0xb9>
jmp    1225 <compare_buffers+0x105>
nop
mov    %r12,%rdx
shl    $0x4,%rdx
mov    0x0(%r13,%rdx,1),%eax
cmp    (%r15,%rdx,1),%eax
jne    120e <compare_buffers+0xee>
test   %eax,%eax
jle    1150 <compare_buffers+0x30>
lea    (%rdx,%r13,1),%r14
movslq %eax,%r8
mov    0x8(%r13,%rdx,1),%rcx
mov    0x8(%r15,%rdx,1),%rdx
xor    %ebp,%ebp
nopl   (%rax)
movzbl (%rcx,%rbp,1),%ebx
cmp    (%rdx,%rbp,1),%bl
jne    11b0 <compare_buffers+0x90>
add    $0x1,%rbp
cmp    %rbp,%rax
jne    1190 <compare_buffers+0x70>
jmp    11d9 <compare_buffers+0xb9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    %rsi,%rbx
lea    0xe4e(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rsi
mov    (%r14),%eax
cmp    %eax,%ebp
jne    1225 <compare_buffers+0x105>
add    $0x1,%r12
cmp    %rsi,%r12
jne    1160 <compare_buffers+0x40>
jmp    122e <compare_buffers+0x10e>
xor    %r12d,%r12d
cmp    %edx,%r12d
je     122e <compare_buffers+0x10e>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    123c <compare_buffers+0x11c>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x4(%rsp),%edx
cmp    %edx,%r12d
jne    11f0 <compare_buffers+0xd0>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i32, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"length mismatch\0A\00"
@.str.1 = [37 x i8] c"index %d, char %d in streamsize %ld\0A\00"
@.str.2 = [14 x i8] c"Tests failed\0A\00"
@.str.3 = [15 x i8] c"Tests passed!\0A\00"
define i32 @compare_buffers(%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
%9 = 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 %10
10: ; preds = %94, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %97
14: ; preds = %10
%15 = load %struct.iovec*, %struct.iovec** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i64 %17
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load %struct.iovec*, %struct.iovec** %6
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i64 %23
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp ne i32 %20, %26
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %97
31: ; preds = %14
store i32 0, i32* %9
br label %32
32: ; preds = %80, %31
%33 = load i32, i32* %9
%34 = load %struct.iovec*, %struct.iovec** %5
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds %struct.iovec, %struct.iovec* %34, i64 %36
%38 = getelementptr inbounds %struct.iovec, %struct.iovec* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = icmp slt i32 %33, %39
br i1 %40, label %41, label %83
41: ; preds = %32
%42 = load %struct.iovec*, %struct.iovec** %5
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %42, i64 %44
%46 = getelementptr inbounds %struct.iovec, %struct.iovec* %45, i32 0, i32 1
%47 = load i64, i64* %46
%48 = inttoptr i64 %47 to i8*
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = load %struct.iovec*, %struct.iovec** %6
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds %struct.iovec, %struct.iovec* %54, i64 %56
%58 = getelementptr inbounds %struct.iovec, %struct.iovec* %57, i32 0, i32 1
%59 = load i64, i64* %58
%60 = inttoptr i64 %59 to i8*
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %53, %65
br i1 %66, label %67, label %79
67: ; preds = %41
%68 = load i32, i32* @stderr
%69 = load i32, i32* %8
%70 = load i32, i32* %9
%71 = load %struct.iovec*, %struct.iovec** %5
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds %struct.iovec, %struct.iovec* %71, i64 %73
%75 = getelementptr inbounds %struct.iovec, %struct.iovec* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = sext i32 %76 to i64
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %69, i32 %70, i64 %77)
br label %83
79: ; preds = %41
br label %80
80: ; preds = %79
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %32
83: ; preds = %67, %32
%84 = load i32, i32* %9
%85 = load %struct.iovec*, %struct.iovec** %5
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds %struct.iovec, %struct.iovec* %85, i64 %87
%89 = getelementptr inbounds %struct.iovec, %struct.iovec* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = icmp ne i32 %84, %90
br i1 %91, label %92, label %93
92: ; preds = %83
br label %97
93: ; preds = %83
br label %94
94: ; preds = %93
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
br label %10
97: ; preds = %92, %28, %10
%98 = load i32, i32* %8
%99 = load i32, i32* %7
%100 = icmp ne i32 %98, %99
br i1 %100, label %101, label %104
101: ; preds = %97
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %106
104: ; preds = %97
%105 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %106
106: ; preds = %104, %101
%107 = load i32, i32* %4
ret i32 %107
}

LLVM IR (-O2):
%struct.iovec = type { i32, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"length mismatch\0A\00"
@.str.1 = [37 x i8] c"index %d, char %d in streamsize %ld\0A\00"
@.str.2 = [14 x i8] c"Tests failed\0A\00"
@str = [14 x i8] c"Tests passed!\00"
define i32 @compare_buffers(%struct.iovec* nocapture %0, %struct.iovec* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %54
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %49
%8 = phi i64 [ 0, %5 ], [ %50, %49 ]
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %0, i64 %8, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %1, i64 %8, i32 0
%12 = load i32, i32* %11
%13 = icmp eq i32 %10, %12
br i1 %13, label %14, label %24
14: ; preds = %7
%15 = icmp sgt i32 %10, 0
br i1 %15, label %16, label %45
16: ; preds = %14
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %0, i64 %8, i32 1
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %1, i64 %8, i32 1
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i8*
%23 = zext i32 %10 to i64
br label %28
24: ; preds = %7
%25 = trunc i64 %8 to i32
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %54
28: ; preds = %16, %42
%29 = phi i64 [ 0, %16 ], [ %43, %42 ]
%30 = getelementptr inbounds i8, i8* %19, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %22, i64 %29
%33 = load i8, i8* %32
%34 = icmp eq i8 %31, %33
br i1 %34, label %42, label %35
35: ; preds = %28
%36 = trunc i64 %29 to i32
%37 = load i32, i32* @stderr
%38 = sext i32 %10 to i64
%39 = trunc i64 %8 to i32
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %36, i64 %38)
%41 = load i32, i32* %9
br label %45
42: ; preds = %28
%43 = add nuw nsw i64 %29, 1
%44 = icmp eq i64 %43, %23
br i1 %44, label %49, label %28
45: ; preds = %14, %35
%46 = phi i32 [ %41, %35 ], [ %10, %14 ]
%47 = phi i32 [ %36, %35 ], [ 0, %14 ]
%48 = icmp eq i32 %47, %46
br i1 %48, label %49, label %52
49: ; preds = %42, %45
%50 = add nuw nsw i64 %8, 1
%51 = icmp eq i64 %50, %6
br i1 %51, label %60, label %7
52: ; preds = %45
%53 = trunc i64 %8 to i32
br label %54
54: ; preds = %52, %3, %24
%55 = phi i32 [ %25, %24 ], [ 0, %3 ], [ %53, %52 ]
%56 = icmp eq i32 %55, %2
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %62
60: ; preds = %49, %54
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %62
62: ; preds = %60, %57
%63 = phi i32 [ -1, %57 ], [ 0, %60 ]
ret i32 %63
}