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

/* Variables and functions */
void tcmu_seek_in_iovec(struct iovec *iovec, size_t count) {
  while (count) {
    if (count >= iovec->iov_len) {
      count -= iovec->iov_len;
      iovec->iov_len = 0;
      iovec++;
    } else {
      iovec->iov_base += count;
      iovec->iov_len -= count;
      count = 0;
    }
  }
}


x86 assembly (clang, -O0):
<tcmu_seek_in_iovec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1184 <tcmu_seek_in_iovec+0x84>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jb     1156 <tcmu_seek_in_iovec+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    117f <tcmu_seek_in_iovec+0x7f>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movq   $0x0,-0x10(%rbp)
jmp    110c <tcmu_seek_in_iovec+0xc>
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcmu_seek_in_iovec>:
test   %rsi,%rsi
je     1128 <tcmu_seek_in_iovec+0x28>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rdi),%rax
cmp    %rax,%rsi
jb     1129 <tcmu_seek_in_iovec+0x29>
movq   $0x0,(%rdi)
add    $0x10,%rdi
sub    %rax,%rsi
jne    1110 <tcmu_seek_in_iovec+0x10>
ret
add    %rsi,0x8(%rdi)
sub    %rsi,%rax
mov    %rax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.iovec = type { i64, i64 }
define void @tcmu_seek_in_iovec(%struct.iovec* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2, %15
%5 = phi i64 [ %16, %15 ], [ %1, %2 ]
%6 = phi %struct.iovec* [ %17, %15 ], [ %0, %2 ]
%7 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp ult i64 %5, %8
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add i64 %12, %5
store i64 %13, i64* %11
%14 = sub i64 %8, %5
store i64 %14, i64* %7
br label %19
15: ; preds = %4
%16 = sub i64 %5, %8
store i64 0, i64* %7
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 1
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %4
19: ; preds = %15, %10, %2
ret void
}