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

/* Variables and functions */
int /*<<< orphan*/ ULONG_MAX;
int /*<<< orphan*/ iovec_cursor_full(struct iovec_cursor *);
int /*<<< orphan*/ iovec_cursor_get(struct iovec *, struct iovec_cursor *,
                                    int /*<<< orphan*/);
int varbuf_copy_in(struct varbuf *, int /*<<< orphan*/, int /*<<< orphan*/);
int __attribute__((unused))
varbuf_copy_iovec_cursor(struct varbuf *vb, struct iovec_cursor *c) {
  while (!iovec_cursor_full(c)) {
    struct iovec iov;
    iovec_cursor_get(&iov, c, ULONG_MAX);
    if (varbuf_copy_in(vb, iov.iov_base, iov.iov_len) == -1)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<varbuf_copy_iovec_cursor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <iovec_cursor_full@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115e <varbuf_copy_iovec_cursor+0x2e>
jmp    119d <varbuf_copy_iovec_cursor+0x6d>
mov    -0x18(%rbp),%rsi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1050 <iovec_cursor_get@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <varbuf_copy_in@plt>
cmp    $0xffffffff,%eax
jne    1198 <varbuf_copy_iovec_cursor+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <varbuf_copy_iovec_cursor+0x74>
jmp    1140 <varbuf_copy_iovec_cursor+0x10>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<varbuf_copy_iovec_cursor>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e93(%rip),%r12
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <iovec_cursor_full@plt>
test   %eax,%eax
jne    1183 <varbuf_copy_iovec_cursor+0x53>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <iovec_cursor_get@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <varbuf_copy_in@plt>
cmp    $0xffffffff,%eax
jne    1150 <varbuf_copy_iovec_cursor+0x20>
xor    %eax,%eax
jmp    1188 <varbuf_copy_iovec_cursor+0x58>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.varbuf = type { i32 }
%struct.iovec_cursor = type { i32 }
%struct.iovec = type { i32, i32 }
@ULONG_MAX = global i32 0
define i32 @varbuf_copy_iovec_cursor(%struct.varbuf* %0, %struct.iovec_cursor* %1) {
%3 = alloca i32
%4 = alloca %struct.varbuf*
%5 = alloca %struct.iovec_cursor*
%6 = alloca %struct.iovec
store %struct.varbuf* %0, %struct.varbuf** %4
store %struct.iovec_cursor* %1, %struct.iovec_cursor** %5
br label %7
7: ; preds = %24, %2
%8 = load %struct.iovec_cursor*, %struct.iovec_cursor** %5
%9 = call i32 @iovec_cursor_full(%struct.iovec_cursor* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = load %struct.iovec_cursor*, %struct.iovec_cursor** %5
%14 = load i32, i32* @ULONG_MAX
%15 = call i32 @iovec_cursor_get(%struct.iovec* %6, %struct.iovec_cursor* %13, i32 %14)
%16 = load %struct.varbuf*, %struct.varbuf** %4
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @varbuf_copy_in(%struct.varbuf* %16, i32 %18, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %12
store i32 0, i32* %3
br label %26
24: ; preds = %12
br label %7
25: ; preds = %7
store i32 1, i32* %3
br label %26
26: ; preds = %25, %23
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.varbuf = type { i32 }
%struct.iovec_cursor = type { i32 }
%struct.iovec = type { i32, i32 }
@ULONG_MAX = global i32 0
define i32 @varbuf_copy_iovec_cursor(%struct.varbuf* %0, %struct.iovec_cursor* %1) {
%3 = alloca %struct.iovec
%4 = bitcast %struct.iovec* %3 to i8*
%5 = getelementptr inbounds %struct.iovec, %struct.iovec* %3, i64 0, i32 1
%6 = getelementptr inbounds %struct.iovec, %struct.iovec* %3, i64 0, i32 0
br label %7
7: ; preds = %10, %2
%8 = call i32 @iovec_cursor_full(%struct.iovec_cursor* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* @ULONG_MAX
%12 = call i32 @iovec_cursor_get(%struct.iovec* %3, %struct.iovec_cursor* %1, i32 %11)
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = call i32 @varbuf_copy_in(%struct.varbuf* %0, i32 %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %7
17: ; preds = %10, %7
%18 = phi i32 [ 0, %10 ], [ 1, %7 ]
ret i32 %18
}