#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 */
int /*<<< orphan*/ merror(char *);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
int write_from(int fp, char *buf, int size) {
  int w = 0, written = 0;
  while (written < size) {
    if ((w = write(fp, buf + written, size - written)) < 0) {
      int err;
      perror("yes...");
      err = 0;
      size = 3 / err;
      merror("Writing a block");
    }
    written += w;
  }
  return written;
}


x86 assembly (clang, -O0):
<write_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ba <write_from+0x8a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11ac <write_from+0x7c>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x20(%rbp)
mov    $0x3,%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x14(%rbp)
lea    0xe60(%rip),%rdi
call   1050 <merror@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <write_from+0x20>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_from>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1197 <write_from+0x67>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
lea    0xeb7(%rip),%r13
jmp    1167 <write_from+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r12d,%ebp
cmp    %ebx,%ebp
jge    1199 <write_from+0x69>
movslq %ebp,%rax
lea    (%r14,%rax,1),%rsi
mov    %ebx,%edx
sub    %eax,%edx
mov    %r15d,%edi
call   1030 <write@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1160 <write_from+0x30>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
mov    %r13,%rdi
call   1050 <merror@plt>
jmp    1160 <write_from+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"yes...\00"
@.str.1 = [16 x i8] c"Writing a block\00"
define i32 @write_from(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %30, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i32, i32* %6
%21 = load i32, i32* %8
%22 = sub nsw i32 %20, %21
%23 = call i32 @write(i32 %15, i8* %19, i32 %22)
store i32 %23, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
%27 = load i32, i32* %9
%28 = sdiv i32 3, %27
store i32 %28, i32* %6
%29 = call i32 @merror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %25, %14
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = add nsw i32 %32, %31
store i32 %33, i32* %8
br label %10
34: ; preds = %10
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
@.str = [7 x i8] c"yes...\00"
@.str.1 = [16 x i8] c"Writing a block\00"
define i32 @write_from(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3, %15
%6 = phi i32 [ %16, %15 ], [ 0, %3 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = sub nsw i32 %2, %6
%10 = tail call i32 @write(i32 %0, i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @merror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %5
%16 = add nsw i32 %10, %6
%17 = icmp slt i32 %16, %2
br i1 %17, label %5, label %18
18: ; preds = %15, %3
%19 = phi i32 [ 0, %3 ], [ %16, %15 ]
ret i32 %19
}