#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 */

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int buffer_stubborn(int (*op)(), int fd, const char *buf, unsigned int len) {
  int w;
  while (len) {
    if ((w = op(fd, buf, len)) < 0) {
      if (errno == EINTR)
        continue;
      return -1;
    };
    buf += w;
    len -= w;
  }
  return 0;
}


x86 assembly (clang, -O0):
<buffer_stubborn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     118a <buffer_stubborn+0x8a>
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x0,%al
call   *%rcx
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1169 <buffer_stubborn+0x69>
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jne    115d <buffer_stubborn+0x5d>
jmp    1116 <buffer_stubborn+0x16>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <buffer_stubborn+0x91>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    1116 <buffer_stubborn+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_stubborn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
je     1155 <buffer_stubborn+0x55>
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2ebf(%rip),%r12
mov    0x2eb0(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   *%rbp
test   %eax,%eax
jns    114c <buffer_stubborn+0x4c>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1130 <buffer_stubborn+0x30>
jmp    1159 <buffer_stubborn+0x59>
mov    %eax,%ecx
add    %rcx,%r14
sub    %eax,%ebx
jne    1130 <buffer_stubborn+0x30>
xor    %eax,%eax
jmp    115e <buffer_stubborn+0x5e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @buffer_stubborn(i32 (...)* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32 (...)*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 (...)* %0, i32 (...)** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
br label %11
11: ; preds = %28, %26, %4
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load i32 (...)*, i32 (...)** %6
%16 = load i32, i32* %7
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = bitcast i32 (...)* %15 to i32 (i32, i8*, i32, ...)*
%20 = call i32 (i32, i8*, i32, ...) %19(i32 %16, i8* %17, i32 %18)
store i32 %20, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
br label %11
27: ; preds = %22
store i32 -1, i32* %5
br label %37
28: ; preds = %14
%29 = load i32, i32* %10
%30 = load i8*, i8** %8
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %8
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = sub i32 %34, %33
store i32 %35, i32* %9
br label %11
36: ; preds = %11
store i32 0, i32* %5
br label %37
37: ; preds = %36, %27
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @buffer_stubborn(i32 (...)* nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = bitcast i32 (...)* %0 to i32 (i32, i8*, i32, ...)*
%6 = icmp eq i32 %3, 0
br i1 %6, label %22, label %7
7: ; preds = %4, %17
%8 = phi i32 [ %20, %17 ], [ %3, %4 ]
%9 = phi i8* [ %19, %17 ], [ %2, %4 ]
br label %10
10: ; preds = %7, %13
%11 = tail call i32 (i32, i8*, i32, ...) %5(i32 %1, i8* %9, i32 %8)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %10, label %22
17: ; preds = %10
%18 = zext i32 %11 to i64
%19 = getelementptr inbounds i8, i8* %9, i64 %18
%20 = sub i32 %8, %11
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %7
22: ; preds = %17, %13, %4
%23 = phi i32 [ 0, %4 ], [ -1, %13 ], [ 0, %17 ]
ret i32 %23
}