#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 */
typedef int mode_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ bail(char *, ...);
int ceil(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ compute(char const *, double);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int, int);
int /*<<< orphan*/ prep_output(char *);
int /*<<< orphan*/ printf(char *, long, ...);
int write(int, char *, int);
void compute_write(const char *task_mode, double task_length,
                   char **output_files, int *output_sizes, int bufsize,
                   int num_output) {
  int i;
  int ret;
  int num_writes = 0;
  for (i = 0; i < num_output; i++) {
    num_writes = num_writes + ceil(output_sizes[i] / (double)bufsize);
  }
  double task_interval = (double)(task_length / (double)num_writes);
  printf("task interval: %f\n", task_interval);
  char *buffer = malloc(bufsize * sizeof(char));
  if (NULL == buffer)
    bail("cannot allocate buffer (%d bytes)", bufsize);
  memset(buffer, 'a', bufsize);
  for (i = 0; i < num_output; i++) {
    int fd;
    int size;
    int count = 0;
    long int total_size = 0;
    prep_output(output_files[i]);
    mode_t mode = S_IRUSR | S_IWUSR;
    fd = open(output_files[i], O_CREAT | O_TRUNC | O_RDWR, mode);
    if (fd < 0)
      bail("cannot open 5 %s", output_files[i]);
    while (total_size < output_sizes[i]) {
      compute(task_mode, task_interval);
      if (output_sizes[i] - total_size > bufsize)
        size = write(fd, buffer, bufsize);
      else
        size = write(fd, buffer, output_sizes[i] - total_size);
      if (size < 0)
        bail("cannot write to %s", output_files[i]);
      total_size = total_size + size;
      count++;
      if (count % 1000 == 0)
        printf("write operations: %d total_size: %ld output_size: %d\n", count,
               total_size, output_sizes[i]);
    }
    printf("write: %ld bytes to %s with bufsize: %d\n", total_size,
           output_files[i], bufsize);
    close(fd);
  }
  return;
}


x86 assembly (clang, -O0):
<compute_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1217 <compute_write+0x77>
mov    -0x34(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ceil@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ce <compute_write+0x2e>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x40(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
jne    126e <compute_write+0xce>
mov    -0x24(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   10a0 <bail@plt>
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    $0x61,%esi
call   1060 <memset@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    144b <compute_write+0x2ab>
movl   $0x0,-0x54(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <prep_output@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    0x2d0e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    0x2d0d(%rip),%rax
or     (%rax),%esi
mov    0x2cec(%rip),%rax
or     (%rax),%esi
mov    -0x64(%rbp),%edx
call   1090 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    131d <compute_write+0x17d>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   10a0 <bail@plt>
jmp    1322 <compute_write+0x182>
mov    -0x60(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmp    %rcx,%rax
jge    1414 <compute_write+0x274>
mov    -0x8(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
call   10c0 <compute@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
sub    -0x60(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jle    137d <compute_write+0x1dd>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x50(%rbp)
jmp    139e <compute_write+0x1fe>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
sub    -0x60(%rbp),%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    13c2 <compute_write+0x222>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   10a0 <bail@plt>
mov    -0x60(%rbp),%rax
movslq -0x50(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    140f <compute_write+0x26f>
movslq -0x54(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xc51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1322 <compute_write+0x182>
mov    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x24(%rbp),%ecx
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edi
call   1070 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1286 <compute_write+0xe6>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,%r13d
mov    %ecx,%r12d
movsd  %xmm0,0x28(%rsp)
mov    %rdi,0x40(%rsp)
mov    %r8d,%eax
mov    %rax,0x18(%rsp)
test   %r8d,%r8d
mov    %ecx,0x14(%rsp)
mov    %rsi,0x20(%rsp)
jle    11ea <compute_write+0x4a>
mov    %rdx,%rbx
cvtsi2sd %r12d,%xmm1
cmp    $0x1,%r13d
jne    11f9 <compute_write+0x59>
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1259 <compute_write+0xb9>
mov    %rsi,%rbx
mov    %rdx,%r15
xorpd  %xmm0,%xmm0
jmp    128c <compute_write+0xec>
mov    0x18(%rsp),%r12
and    $0xfffffffe,%r12d
xor    %r15d,%r15d
xor    %ebp,%ebp
movsd  %xmm1,0x8(%rsp)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx,%r15,4),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ceil@plt>
mov    %eax,%r14d
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rbx,%r15,4),%xmm0
add    %ebp,%r14d
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ceil@plt>
movsd  0x8(%rsp),%xmm1
mov    %eax,%ebp
add    %r14d,%ebp
add    $0x2,%r15
cmp    %r15,%r12
jne    1210 <compute_write+0x70>
testb  $0x1,0x18(%rsp)
je     1278 <compute_write+0xd8>
xorps  %xmm0,%xmm0
cvtsi2sdl (%rbx,%r15,4),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ceil@plt>
add    %eax,%ebp
mov    %rbx,%r15
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mov    0x14(%rsp),%r12d
mov    0x20(%rsp),%rbx
movsd  0x28(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
cvttsd2si %xmm1,%rsi
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    12d3 <compute_write+0x133>
lea    0xd50(%rip),%rdi
mov    %rax,%r14
mov    %r12d,%esi
xor    %eax,%eax
call   10a0 <bail@plt>
mov    %r14,%rax
mov    %rax,0x38(%rsp)
mov    %rax,%rdi
mov    $0x61,%esi
mov    %r12d,%edx
call   1060 <memset@plt>
test   %r13d,%r13d
jle    1465 <compute_write+0x2c5>
mov    %r15,%r13
movslq %r12d,%rax
mov    %rax,0x30(%rsp)
xor    %ebp,%ebp
jmp    133b <compute_write+0x19b>
xor    %r14d,%r14d
mov    %rax,%rbp
mov    0x20(%rsp),%rbx
mov    (%rbx,%rbp,8),%rdx
lea    0xd79(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
add    $0x1,%rbp
cmp    0x18(%rsp),%rbp
je     1465 <compute_write+0x2c5>
mov    (%rbx,%rbp,8),%rdi
call   10b0 <prep_output@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edx
mov    0x2c6c(%rip),%rax
or     (%rax),%edx
mov    (%rbx,%rbp,8),%rdi
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
mov    0x2c8e(%rip),%rax
or     (%rax),%esi
mov    0x2c65(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
jns    1394 <compute_write+0x1f4>
mov    (%rbx,%rbp,8),%rsi
lea    0xca8(%rip),%rdi
xor    %eax,%eax
call   10a0 <bail@plt>
mov    %rbp,%rax
cmpl   $0x0,0x0(%r13,%rbp,4)
jle    1300 <compute_write+0x160>
mov    $0x1,%r15d
xor    %r14d,%r14d
mov    %rax,%rbp
jmp    13d7 <compute_write+0x237>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq 0x0(%r13,%rbp,4),%rax
add    $0x1,%r15
cmp    %rax,%r14
mov    0x14(%rsp),%r12d
jge    1306 <compute_write+0x166>
mov    %r15d,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0xfffffc18,%eax,%ebx
mov    0x40(%rsp),%rdi
movsd  0x28(%rsp),%xmm0
call   10c0 <compute@plt>
movslq 0x0(%r13,%rbp,4),%rdx
sub    %r14,%rdx
cmp    0x30(%rsp),%rdx
cmovg  %r12d,%edx
mov    0x8(%rsp),%edi
mov    0x38(%rsp),%rsi
call   1030 <write@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1438 <compute_write+0x298>
mov    0x20(%rsp),%rax
mov    (%rax,%rbp,8),%rsi
lea    0xc15(%rip),%rdi
xor    %eax,%eax
call   10a0 <bail@plt>
movslq %r12d,%rax
add    %rax,%r14
add    %r15d,%ebx
jne    13c0 <compute_write+0x220>
mov    0x0(%r13,%rbp,4),%ecx
lea    0xc06(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13c0 <compute_write+0x220>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"task interval: %f\0A\00"
@.str.1 = [34 x i8] c"cannot allocate buffer (%d bytes)\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.2 = [17 x i8] c"cannot open 5 %s\00"
@.str.3 = [19 x i8] c"cannot write to %s\00"
@.str.4 = [54 x i8] c"write operations: %d total_size: %ld output_size: %d\0A\00"
@.str.5 = [41 x i8] c"write: %ld bytes to %s with bufsize: %d\0A\00"
define void @compute_write(i8* %0, double %1, i8** %2, i32* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca double
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i64
%22 = alloca i32
store i8* %0, i8** %7
store double %1, double* %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %15
store i32 0, i32* %13
br label %23
23: ; preds = %41, %6
%24 = load i32, i32* %13
%25 = load i32, i32* %12
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %44
27: ; preds = %23
%28 = load i32, i32* %15
%29 = load i32*, i32** %10
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = sitofp i32 %33 to double
%35 = load i32, i32* %11
%36 = sitofp i32 %35 to double
%37 = fdiv double %34, %36
%38 = fptosi double %37 to i32
%39 = call i32 @ceil(i32 %38)
%40 = add nsw i32 %28, %39
store i32 %40, i32* %15
br label %41
41: ; preds = %27
%42 = load i32, i32* %13
%43 = add nsw i32 %42, 1
store i32 %43, i32* %13
br label %23
44: ; preds = %23
%45 = load double, double* %8
%46 = load i32, i32* %15
%47 = sitofp i32 %46 to double
%48 = fdiv double %45, %47
store double %48, double* %16
%49 = load double, double* %16
%50 = fptosi double %49 to i64
%51 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %50)
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 1
%55 = trunc i64 %54 to i32
%56 = call i8* @malloc(i32 %55)
store i8* %56, i8** %17
%57 = load i8*, i8** %17
%58 = icmp eq i8* null, %57
br i1 %58, label %59, label %62
59: ; preds = %44
%60 = load i32, i32* %11
%61 = call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %44
%63 = load i8*, i8** %17
%64 = load i32, i32* %11
%65 = call i32 @memset(i8* %63, i8 signext 97, i32 %64)
store i32 0, i32* %13
br label %66
66: ; preds = %186, %62
%67 = load i32, i32* %13
%68 = load i32, i32* %12
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %189
70: ; preds = %66
store i32 0, i32* %20
store i64 0, i64* %21
%71 = load i8**, i8*** %9
%72 = load i32, i32* %13
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @prep_output(i8* %75)
%77 = load i32, i32* @S_IRUSR
%78 = load i32, i32* @S_IWUSR
%79 = or i32 %77, %78
store i32 %79, i32* %22
%80 = load i8**, i8*** %9
%81 = load i32, i32* %13
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8*, i8** %80, i64 %82
%84 = load i8*, i8** %83
%85 = load i32, i32* @O_CREAT
%86 = load i32, i32* @O_TRUNC
%87 = or i32 %85, %86
%88 = load i32, i32* @O_RDWR
%89 = or i32 %87, %88
%90 = load i32, i32* %22
%91 = call i32 @open(i8* %84, i32 %89, i32 %90)
store i32 %91, i32* %18
%92 = load i32, i32* %18
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %70
%95 = load i8**, i8*** %9
%96 = load i32, i32* %13
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %95, i64 %97
%99 = load i8*, i8** %98
%100 = call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %94, %70
br label %102
102: ; preds = %174, %101
%103 = load i64, i64* %21
%104 = load i32*, i32** %10
%105 = load i32, i32* %13
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %104, i64 %106
%108 = load i32, i32* %107
%109 = sext i32 %108 to i64
%110 = icmp slt i64 %103, %109
br i1 %110, label %111, label %175
111: ; preds = %102
%112 = load i8*, i8** %7
%113 = load double, double* %16
%114 = call i32 @compute(i8* %112, double %113)
%115 = load i32*, i32** %10
%116 = load i32, i32* %13
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i32, i32* %115, i64 %117
%119 = load i32, i32* %118
%120 = sext i32 %119 to i64
%121 = load i64, i64* %21
%122 = sub nsw i64 %120, %121
%123 = load i32, i32* %11
%124 = sext i32 %123 to i64
%125 = icmp sgt i64 %122, %124
br i1 %125, label %126, label %131
126: ; preds = %111
%127 = load i32, i32* %18
%128 = load i8*, i8** %17
%129 = load i32, i32* %11
%130 = call i32 @write(i32 %127, i8* %128, i32 %129)
store i32 %130, i32* %19
br label %144
131: ; preds = %111
%132 = load i32, i32* %18
%133 = load i8*, i8** %17
%134 = load i32*, i32** %10
%135 = load i32, i32* %13
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i32, i32* %134, i64 %136
%138 = load i32, i32* %137
%139 = sext i32 %138 to i64
%140 = load i64, i64* %21
%141 = sub nsw i64 %139, %140
%142 = trunc i64 %141 to i32
%143 = call i32 @write(i32 %132, i8* %133, i32 %142)
store i32 %143, i32* %19
br label %144
144: ; preds = %131, %126
%145 = load i32, i32* %19
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %154
147: ; preds = %144
%148 = load i8**, i8*** %9
%149 = load i32, i32* %13
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8*, i8** %148, i64 %150
%152 = load i8*, i8** %151
%153 = call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %152)
br label %154
154: ; preds = %147, %144
%155 = load i64, i64* %21
%156 = load i32, i32* %19
%157 = sext i32 %156 to i64
%158 = add nsw i64 %155, %157
store i64 %158, i64* %21
%159 = load i32, i32* %20
%160 = add nsw i32 %159, 1
store i32 %160, i32* %20
%161 = load i32, i32* %20
%162 = srem i32 %161, 1000
%163 = icmp eq i32 %162, 0
br i1 %163, label %164, label %174
164: ; preds = %154
%165 = load i32, i32* %20
%166 = sext i32 %165 to i64
%167 = load i64, i64* %21
%168 = load i32*, i32** %10
%169 = load i32, i32* %13
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i32, i32* %168, i64 %170
%172 = load i32, i32* %171
%173 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i64 %166, i64 %167, i32 %172)
br label %174
174: ; preds = %164, %154
br label %102
175: ; preds = %102
%176 = load i64, i64* %21
%177 = load i8**, i8*** %9
%178 = load i32, i32* %13
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i8*, i8** %177, i64 %179
%181 = load i8*, i8** %180
%182 = load i32, i32* %11
%183 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %176, i8* %181, i32 %182)
%184 = load i32, i32* %18
%185 = call i32 @close(i32 %184)
br label %186
186: ; preds = %175
%187 = load i32, i32* %13
%188 = add nsw i32 %187, 1
store i32 %188, i32* %13
br label %66
189: ; preds = %66
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"task interval: %f\0A\00"
@.str.1 = [34 x i8] c"cannot allocate buffer (%d bytes)\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.2 = [17 x i8] c"cannot open 5 %s\00"
@.str.3 = [19 x i8] c"cannot write to %s\00"
@.str.4 = [54 x i8] c"write operations: %d total_size: %ld output_size: %d\0A\00"
@.str.5 = [41 x i8] c"write: %ld bytes to %s with bufsize: %d\0A\00"
define void @compute_write(i8* %0, double %1, i8** nocapture %2, i32* nocapture %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %53
8: ; preds = %6
%9 = sitofp i32 %4 to double
%10 = zext i32 %5 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %5, 1
br i1 %12, label %37, label %13
13: ; preds = %8
%14 = and i64 %10, 4294967294
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %34, %15 ]
%17 = phi i32 [ 0, %13 ], [ %33, %15 ]
%18 = phi i64 [ 0, %13 ], [ %35, %15 ]
%19 = getelementptr inbounds i32, i32* %3, i64 %16
%20 = load i32, i32* %19
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, %9
%23 = fptosi double %22 to i32
%24 = tail call i32 @ceil(i32 %23)
%25 = add nsw i32 %24, %17
%26 = or i64 %16, 1
%27 = getelementptr inbounds i32, i32* %3, i64 %26
%28 = load i32, i32* %27
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, %9
%31 = fptosi double %30 to i32
%32 = tail call i32 @ceil(i32 %31)
%33 = add nsw i32 %32, %25
%34 = add nuw nsw i64 %16, 2
%35 = add i64 %18, 2
%36 = icmp eq i64 %35, %14
br i1 %36, label %37, label %15
37: ; preds = %15, %8
%38 = phi i32 [ undef, %8 ], [ %33, %15 ]
%39 = phi i64 [ 0, %8 ], [ %34, %15 ]
%40 = phi i32 [ 0, %8 ], [ %33, %15 ]
%41 = icmp eq i64 %11, 0
br i1 %41, label %50, label %42
42: ; preds = %37
%43 = getelementptr inbounds i32, i32* %3, i64 %39
%44 = load i32, i32* %43
%45 = sitofp i32 %44 to double
%46 = fdiv double %45, %9
%47 = fptosi double %46 to i32
%48 = tail call i32 @ceil(i32 %47)
%49 = add nsw i32 %48, %40
br label %50
50: ; preds = %37, %42
%51 = phi i32 [ %38, %37 ], [ %49, %42 ]
%52 = sitofp i32 %51 to double
br label %53
53: ; preds = %50, %6
%54 = phi double [ 0.000000e+00, %6 ], [ %52, %50 ]
%55 = fdiv double %1, %54
%56 = fptosi double %55 to i64
%57 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %56)
%58 = sext i32 %4 to i64
%59 = tail call i8* @malloc(i32 %4)
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %53
%62 = tail call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %63
63: ; preds = %61, %53
%64 = tail call i32 @memset(i8* %59, i8 signext 97, i32 %4)
br i1 %7, label %65, label %126
65: ; preds = %63
%66 = zext i32 %5 to i64
br label %67
67: ; preds = %65, %119
%68 = phi i64 [ 0, %65 ], [ %124, %119 ]
%69 = getelementptr inbounds i8*, i8** %2, i64 %68
%70 = load i8*, i8** %69
%71 = tail call i32 @prep_output(i8* %70)
%72 = load i32, i32* @S_IRUSR
%73 = load i32, i32* @S_IWUSR
%74 = or i32 %73, %72
%75 = load i8*, i8** %69
%76 = load i32, i32* @O_CREAT
%77 = load i32, i32* @O_TRUNC
%78 = or i32 %77, %76
%79 = load i32, i32* @O_RDWR
%80 = or i32 %78, %79
%81 = tail call i32 @open(i8* %75, i32 %80, i32 %74)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %67
%84 = load i8*, i8** %69
%85 = tail call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %83, %67
%87 = getelementptr inbounds i32, i32* %3, i64 %68
%88 = load i32, i32* %87
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %119
90: ; preds = %86, %115
%91 = phi i64 [ %108, %115 ], [ 0, %86 ]
%92 = phi i64 [ %107, %115 ], [ 0, %86 ]
%93 = tail call i32 @compute(i8* %0, double %55)
%94 = load i32, i32* %87
%95 = sext i32 %94 to i64
%96 = sub nsw i64 %95, %92
%97 = icmp sgt i64 %96, %58
%98 = trunc i64 %96 to i32
%99 = select i1 %97, i32 %4, i32 %98
%100 = tail call i32 @write(i32 %81, i8* %59, i32 %99)
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %90
%103 = load i8*, i8** %69
%104 = tail call i32 (i8*, ...) @bail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %102, %90
%106 = sext i32 %100 to i64
%107 = add nsw i64 %92, %106
%108 = add nuw i64 %91, 1
%109 = trunc i64 %108 to i32
%110 = urem i32 %109, 1000
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %105
%113 = load i32, i32* %87
%114 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i64 %108, i64 %107, i32 %113)
br label %115
115: ; preds = %112, %105
%116 = load i32, i32* %87
%117 = sext i32 %116 to i64
%118 = icmp slt i64 %107, %117
br i1 %118, label %90, label %119
119: ; preds = %115, %86
%120 = phi i64 [ 0, %86 ], [ %107, %115 ]
%121 = load i8*, i8** %69
%122 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %120, i8* %121, i32 %4)
%123 = tail call i32 @close(i32 %81)
%124 = add nuw nsw i64 %68, 1
%125 = icmp eq i64 %124, %66
br i1 %125, label %126, label %67
126: ; preds = %119, %63
ret void
}