#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__ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int output(FILE *f, unsigned int count, char begin, char end) {
  unsigned int i;
  char c = begin;
  for (i = 0; i < count; ++i) {
    if (fputc(c, f) == EOF)
      goto exit_bad_fputc;
    if (c == end)
      c = begin;
    else
      ++c;
  }
  if (fflush(f) == EOF)
    goto exit_bad_fflush;
  return 0;
exit_bad_fputc:
  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    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %cl,-0x15(%rbp)
mov    %al,-0x16(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x1d(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11bc <output+0x8c>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <output+0x56>
jmp    11e6 <output+0xb6>
movsbl -0x1d(%rbp),%eax
movsbl -0x16(%rbp),%ecx
cmp    %ecx,%eax
jne    11a1 <output+0x71>
mov    -0x15(%rbp),%al
mov    %al,-0x1d(%rbp)
jmp    11a9 <output+0x79>
mov    -0x1d(%rbp),%al
add    $0x1,%al
mov    %al,-0x1d(%rbp)
jmp    11ae <output+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <output+0x26>
mov    -0x10(%rbp),%rdi
call   1040 <fflush@plt>
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%rax
jne    11da <output+0xaa>
jmp    11f7 <output+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    120a <output+0xda>
lea    0xe13(%rip),%rdi
call   1050 <perror@plt>
jmp    1203 <output+0xd3>
lea    0xe15(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %esi,%esi
je     1183 <output+0x53>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
mov    0x2e98(%rip),%r13
movzbl %bl,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %bl,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
cmp    0x0(%r13),%rax
je     11b4 <output+0x84>
lea    0x1(%rbx),%eax
cmp    %r14b,%bl
movzbl %al,%ebx
cmove  %r12d,%ebx
add    $0xffffffff,%ebp
jne    1160 <output+0x30>
mov    %r15,%rdi
call   1040 <fflush@plt>
mov    %rax,%rcx
mov    0x2e53(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     11ab <output+0x7b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe61(%rip),%rdi
jmp    11bb <output+0x8b>
lea    0xe45(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    119c <output+0x6c>

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

LLVM IR (-O2):
@EOF = global i64 0
@.str = [19 x i8] c"error writing data\00"
@.str.1 = [20 x i8] c"error flushing file\00"
define i32 @output(i32* nocapture %0, i32 %1, i8 signext %2, i8 signext %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %18, label %6
6: ; preds = %4, %12
%7 = phi i8 [ %15, %12 ], [ %2, %4 ]
%8 = phi i32 [ %16, %12 ], [ 0, %4 ]
%9 = tail call i64 @fputc(i8 signext %7, i32* %0)
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %22, label %12
12: ; preds = %6
%13 = icmp eq i8 %7, %3
%14 = add i8 %7, 1
%15 = select i1 %13, i8 %2, i8 %14
%16 = add nuw i32 %8, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %6
18: ; preds = %12, %4
%19 = tail call i64 @fflush(i32* %0)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %6, %18
%23 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %6 ]
%24 = tail call i32 @perror(i8* %23)
br label %25
25: ; preds = %22, %18
%26 = phi i32 [ 0, %18 ], [ -1, %22 ]
ret i32 %26
}