#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int counter = 0;
  while (1) {
    fprintf(stdout, "running (out) %i\n", counter);
    fprintf(stderr, "running (err) %i\n", counter++);
    if (fflush(NULL) < 0) {
      fprintf(stderr, "Error flushing output streams\n");
      exit(EXIT_FAILURE);
    }
    (void)sleep(5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
cmp    $0x0,%rax
jge    11d1 <main+0x91>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    115d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x2e80(%rip),%r12
mov    (%r12),%edi
lea    0xea5(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e75(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe9c(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
test   %rax,%rax
js     11d9 <main+0x99>
mov    $0x1,%ebx
lea    0xe69(%rip),%r14
lea    0xe74(%rip),%r15
xchg   %ax,%ax
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
add    $0x1,%ebx
test   %rax,%rax
jns    11a0 <main+0x60>
mov    0x0(%r13),%edi
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [18 x i8] c"running (out) %i\0A\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"running (err) %i\0A\00"
@.str.2 = [31 x i8] c"Error flushing output streams\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %7
7: ; preds = %2, %22
%8 = load i32, i32* @stdout
%9 = load i32, i32* %6
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @stderr
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%15 = call i64 @fflush(i32* null)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %7
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %7
%23 = call i32 @sleep(i32 5)
br label %7
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [18 x i8] c"running (out) %i\0A\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"running (err) %i\0A\00"
@.str.2 = [31 x i8] c"Error flushing output streams\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 0)
%7 = tail call i64 @fflush(i32* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %14, %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2, %14
%15 = phi i32 [ %16, %14 ], [ 0, %2 ]
%16 = add nuw nsw i32 %15, 1
%17 = tail call i32 @sleep(i32 5)
%18 = load i32, i32* @stdout
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %16)
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%22 = tail call i64 @fflush(i32* null)
%23 = icmp slt i64 %22, 0
br i1 %23, label %9, label %14
}