#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 /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fflush(int /*<<< orphan*/ *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int output(FILE *f, unsigned int count, unsigned int count2, unsigned int len,
           unsigned int begin, unsigned int end) {
  unsigned int i;
  unsigned int n = begin;
  char str[20];
  for (i = 0; i < count; ++i) {
    sprintf(str, "%u\n", n);
    if (fputs(str, f) == EOF)
      goto exit_bad_fputs;
    if (n == end)
      n = begin;
    else
      ++n;
  }
  if (fflush(f) == EOF)
    goto exit_bad_fflush;
  n = begin;
  for (i = 0; i < count2; ++i) {
    sprintf(str, "%u", n);
    str[len] = '\0';
    if (fputs(str, f) == EOF)
      goto exit_bad_fputs;
    if (n == end)
      n = begin;
    else
      ++n;
  }
  return 0;
exit_bad_fputs:
  perror("error writing data");
  goto exit_fail;
exit_bad_fflush:
  perror("error flushing file");
  goto exit_fail;
exit_fail:
  return -1;
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11de <output+0x9e>
lea    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe7c(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
jne    11ab <output+0x6b>
jmp    1291 <output+0x151>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11c2 <output+0x82>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11cb <output+0x8b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d0 <output+0x90>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116a <output+0x2a>
mov    -0x10(%rbp),%rdi
call   1040 <fflush@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
jne    11fc <output+0xbc>
jmp    12a2 <output+0x162>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1285 <output+0x145>
lea    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xde1(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x1c(%rbp),%eax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
jne    1252 <output+0x112>
jmp    1291 <output+0x151>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1269 <output+0x129>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1272 <output+0x132>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1277 <output+0x137>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1209 <output+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    12b5 <output+0x175>
lea    0xd6f(%rip),%rdi
call   1050 <perror@plt>
jmp    12ae <output+0x16e>
lea    0xd71(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0x8(%rsp)
mov    %r8d,%r15d
mov    %ecx,0xc(%rsp)
mov    %edx,%ebx
mov    %rdi,%r13
test   %esi,%esi
je     11b2 <output+0x72>
mov    %esi,%ebp
lea    0x10(%rsp),%r12
mov    %r15d,%r14d
nopl   (%rax)
mov    %r12,%rdi
lea    0xe86(%rip),%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
je     1231 <output+0xf1>
cmp    0x8(%rsp),%r14d
lea    0x1(%r14),%eax
cmove  %r15d,%eax
mov    %eax,%r14d
add    $0xffffffff,%ebp
jne    1170 <output+0x30>
mov    %r13,%rdi
call   1040 <fflush@plt>
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
je     123a <output+0xfa>
xor    %eax,%eax
test   %ebx,%ebx
je     1222 <output+0xe2>
mov    0xc(%rsp),%r14d
lea    0x10(%rsp),%r12
mov    %r15d,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
lea    0xe1a(%rip),%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
movb   $0x0,0x10(%rsp,%r14,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     1231 <output+0xf1>
cmp    0x8(%rsp),%ebp
lea    0x1(%rbp),%eax
cmove  %r15d,%eax
mov    %eax,%ebp
add    $0xffffffff,%ebx
jne    11e0 <output+0xa0>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcf(%rip),%rdi
jmp    1241 <output+0x101>
lea    0xdd9(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1222 <output+0xe2>

LLVM IR (-O0):
@.str = [4 x i8] c"%u\0A\00"
@EOF = global i64 0
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [19 x i8] c"error writing data\00"
@.str.3 = [20 x i8] c"error flushing file\00"
define i32 @output(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [20 x i8]
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%17 = load i32, i32* %12
store i32 %17, i32* %15
store i32 0, i32* %14
br label %18
18: ; preds = %42, %6
%19 = load i32, i32* %14
%20 = load i32, i32* %9
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%24 = load i32, i32* %15
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%27 = load i32*, i32** %8
%28 = call i64 @fputs(i8* %26, i32* %27)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %22
br label %84
32: ; preds = %22
%33 = load i32, i32* %15
%34 = load i32, i32* %13
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i32, i32* %12
store i32 %37, i32* %15
br label %41
38: ; preds = %32
%39 = load i32, i32* %15
%40 = add i32 %39, 1
store i32 %40, i32* %15
br label %41
41: ; preds = %38, %36
br label %42
42: ; preds = %41
%43 = load i32, i32* %14
%44 = add i32 %43, 1
store i32 %44, i32* %14
br label %18
45: ; preds = %18
%46 = load i32*, i32** %8
%47 = call i64 @fflush(i32* %46)
%48 = load i64, i64* @EOF
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %45
br label %86
51: ; preds = %45
%52 = load i32, i32* %12
store i32 %52, i32* %15
store i32 0, i32* %14
br label %53
53: ; preds = %80, %51
%54 = load i32, i32* %14
%55 = load i32, i32* %10
%56 = icmp ult i32 %54, %55
br i1 %56, label %57, label %83
57: ; preds = %53
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%59 = load i32, i32* %15
%60 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %11
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 %62
store i8 0, i8* %63
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%65 = load i32*, i32** %8
%66 = call i64 @fputs(i8* %64, i32* %65)
%67 = load i64, i64* @EOF
%68 = icmp eq i64 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %57
br label %84
70: ; preds = %57
%71 = load i32, i32* %15
%72 = load i32, i32* %13
%73 = icmp eq i32 %71, %72
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = load i32, i32* %12
store i32 %75, i32* %15
br label %79
76: ; preds = %70
%77 = load i32, i32* %15
%78 = add i32 %77, 1
store i32 %78, i32* %15
br label %79
79: ; preds = %76, %74
br label %80
80: ; preds = %79
%81 = load i32, i32* %14
%82 = add i32 %81, 1
store i32 %82, i32* %14
br label %53
83: ; preds = %53
store i32 0, i32* %7
br label %89
84: ; preds = %69, %31
%85 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %88
86: ; preds = %50
%87 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %88
88: ; preds = %86, %84
store i32 -1, i32* %7
br label %89
89: ; preds = %88, %83
%90 = load i32, i32* %7
ret i32 %90
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u\0A\00"
@EOF = global i64 0
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [19 x i8] c"error writing data\00"
@.str.3 = [20 x i8] c"error flushing file\00"
define i32 @output(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%9 = icmp eq i32 %1, 0
br i1 %9, label %23, label %10
10: ; preds = %6, %17
%11 = phi i32 [ %20, %17 ], [ %4, %6 ]
%12 = phi i32 [ %21, %17 ], [ 0, %6 ]
%13 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%14 = call i64 @fputs(i8* %8, i32* %0)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %45, label %17
17: ; preds = %10
%18 = icmp eq i32 %11, %5
%19 = add i32 %11, 1
%20 = select i1 %18, i32 %4, i32 %19
%21 = add nuw i32 %12, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %23, label %10
23: ; preds = %17, %6
%24 = tail call i64 @fflush(i32* %0)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %45, label %27
27: ; preds = %23
%28 = icmp eq i32 %2, 0
br i1 %28, label %48, label %29
29: ; preds = %27
%30 = zext i32 %3 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %30
br label %32
32: ; preds = %29, %39
%33 = phi i32 [ %4, %29 ], [ %42, %39 ]
%34 = phi i32 [ 0, %29 ], [ %43, %39 ]
%35 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
store i8 0, i8* %31
%36 = call i64 @fputs(i8* %8, i32* %0)
%37 = load i64, i64* @EOF
%38 = icmp eq i64 %36, %37
br i1 %38, label %45, label %39
39: ; preds = %32
%40 = icmp eq i32 %33, %5
%41 = add i32 %33, 1
%42 = select i1 %40, i32 %4, i32 %41
%43 = add nuw i32 %34, 1
%44 = icmp eq i32 %43, %2
br i1 %44, label %48, label %32
45: ; preds = %10, %32, %23
%46 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %23 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %32 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %10 ]
%47 = tail call i32 @perror(i8* %46)
br label %48
48: ; preds = %39, %45, %27
%49 = phi i32 [ 0, %27 ], [ -1, %45 ], [ 0, %39 ]
ret i32 %49
}