#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 uo {
  int dummy;
};
struct ui {
  int dummy;
};

/* Variables and functions */
size_t uio_copy_n(struct ui *, struct uo *, size_t);
size_t uio_copy_while(struct ui *src, struct uo *dst,
                      size_t peek(struct ui *)) {
  size_t wtot = 0;
  size_t w;
  while ((w = uio_copy_n(src, dst, peek(src))))
    wtot += w;
  return wtot;
}


x86 assembly (clang, -O0):
<uio_copy_while>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rdi
call   *%rax
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1030 <uio_copy_n@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1175 <uio_copy_while+0x65>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    112c <uio_copy_while+0x1c>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uio_copy_while>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%rbx
mov    %r12,%rdi
call   *%r14
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <uio_copy_n@plt>
lea    (%rax,%rbx,1),%rcx
test   %rax,%rax
jne    1130 <uio_copy_while+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ui = type { i32 }
%struct.uo = type { i32 }
define i64 @uio_copy_while(%struct.ui* %0, %struct.uo* %1, i64 (%struct.ui*)* %2) {
%4 = alloca %struct.ui*
%5 = alloca %struct.uo*
%6 = alloca i64 (%struct.ui*)*
%7 = alloca i64
%8 = alloca i64
store %struct.ui* %0, %struct.ui** %4
store %struct.uo* %1, %struct.uo** %5
store i64 (%struct.ui*)* %2, i64 (%struct.ui*)** %6
store i64 0, i64* %7
br label %9
9: ; preds = %17, %3
%10 = load %struct.ui*, %struct.ui** %4
%11 = load %struct.uo*, %struct.uo** %5
%12 = load i64 (%struct.ui*)*, i64 (%struct.ui*)** %6
%13 = load %struct.ui*, %struct.ui** %4
%14 = call i64 %12(%struct.ui* %13)
%15 = call i64 @uio_copy_n(%struct.ui* %10, %struct.uo* %11, i64 %14)
store i64 %15, i64* %8
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i64, i64* %8
%19 = load i64, i64* %7
%20 = add i64 %19, %18
store i64 %20, i64* %7
br label %9
21: ; preds = %9
%22 = load i64, i64* %7
ret i64 %22
}

LLVM IR (-O2):
%struct.ui = type { i32 }
%struct.uo = type { i32 }
define i64 @uio_copy_while(%struct.ui* %0, %struct.uo* %1, i64 (%struct.ui*)* nocapture %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ 0, %3 ], [ %9, %4 ]
%6 = tail call i64 %2(%struct.ui* %0)
%7 = tail call i64 @uio_copy_n(%struct.ui* %0, %struct.uo* %1, i64 %6)
%8 = icmp eq i64 %7, 0
%9 = add i64 %7, %5
br i1 %8, label %10, label %4
10: ; preds = %4
ret i64 %5
}