#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 */
char *calloc(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ throw(int /*<<< orphan*/, int /*<<< orphan*/, char *);
scalar_t__ write(int, char *, int);
int do_io(int fd, int size, int count) {
  int i;
  char *buf;
  buf = calloc(1, size);
  if (buf == NULL) {
    return -1;
  }
  for (i = 0; i < count; i++) {
    if (write(fd, buf, size) < 0) {
      throw(0, errno, "error in writing");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <do_io+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <do_io+0xa2>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cb <do_io+0x9b>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b8 <do_io+0x88>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xe59(%rip),%rdx
call   1050 <throw@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <do_io+0xa2>
jmp    11bd <do_io+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <do_io+0x40>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_io>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%r12d
mov    %edi,%r15d
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     1194 <do_io+0x64>
test   %ebp,%ebp
jle    1178 <do_io+0x48>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
test   %rax,%rax
js     117d <do_io+0x4d>
add    $0xffffffff,%ebp
jne    1160 <do_io+0x30>
xor    %r14d,%r14d
jmp    1194 <do_io+0x64>
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdx
xor    %edi,%edi
call   1050 <throw@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [17 x i8] c"error in writing\00"
define i32 @do_io(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = call i8* @calloc(i32 1, i32 %10)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %34
15: ; preds = %3
store i32 0, i32* %8
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i8*, i8** %9
%23 = load i32, i32* %6
%24 = call i64 @write(i32 %21, i8* %22, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* @errno
%28 = call i32 @throw(i32 0, i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %34
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %16
33: ; preds = %16
store i32 0, i32* %4
br label %34
34: ; preds = %33, %26, %14
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [17 x i8] c"error in writing\00"
define i32 @do_io(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @calloc(i32 1, i32 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
br i1 %7, label %10, label %18
8: ; preds = %10
%9 = icmp eq i32 %14, %2
br i1 %9, label %18, label %10
10: ; preds = %6, %8
%11 = phi i32 [ %14, %8 ], [ 0, %6 ]
%12 = tail call i64 @write(i32 %0, i8* %4, i32 %1)
%13 = icmp slt i64 %12, 0
%14 = add nuw nsw i32 %11, 1
br i1 %13, label %15, label %8
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = tail call i32 @throw(i32 0, i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %8, %6, %3, %15
%19 = phi i32 [ -1, %15 ], [ -1, %3 ], [ 0, %6 ], [ 0, %8 ]
ret i32 %19
}