#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 */
struct spinner {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
char spinner_advance(struct spinner *);
struct spinner *spinner_new();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  struct spinner *sp = spinner_new();
  char buffer[128];
  size_t nread;
  if (argc > 1)
    fputs(argv[1], stderr);
  fputs("  ", stderr);
  while ((nread = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
    if (ferror(stdin)) {
      fputc('\n', stderr);
      perror(argv[0]);
      exit(1);
    } else if (feof(stdin)) {
      fputc('\n', stderr);
      exit(0);
    }
    fwrite(buffer, 1, nread, stdout);
    fputs("\b\b", stderr);
    fputc(spinner_advance(sp), stderr);
    fputc(' ', stderr);
  }
  fputs("\b\b\n", stderr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <spinner_new@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11e4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1050 <fputs@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jbe    1309 <main+0x169>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     126a <main+0xca>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     129c <main+0xfc>
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    12a1 <main+0x101>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    0x2d1a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
lea    0xd31(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1080 <spinner_advance@plt>
mov    0x2cf1(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1060 <fputc@plt>
jmp    11f9 <main+0x59>
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
lea    0xced(%rip),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <spinner_new@plt>
mov    %rax,%r15
cmp    $0x2,%ebx
jl     11d7 <main+0x37>
mov    0x8(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    %rbp,0x8(%rsp)
mov    0x2df5(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe13(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2def(%rip),%r14
mov    (%r14),%ecx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
test   %rax,%rax
je     12b7 <main+0x117>
mov    %rax,%rbx
lea    0x10(%rsp),%r13
lea    0xddb(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12da <main+0x13a>
mov    (%r14),%edi
call   1070 <feof@plt>
test   %rax,%rax
jne    12fe <main+0x15e>
mov    0x2d77(%rip),%rax
mov    (%rax),%ecx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   10c0 <fwrite@plt>
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1050 <fputs@plt>
mov    %r15,%rdi
call   1080 <spinner_advance@plt>
mov    0x0(%rbp),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    0x0(%rbp),%esi
mov    $0x20,%edi
call   1060 <fputc@plt>
mov    (%r14),%ecx
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1230 <main+0x90>
mov    0x0(%rbp),%esi
lea    0xd45(%rip),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x0(%rbp),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.spinner = type { i32 }
@stderr = global i32 0
@.str = [3 x i8] c" \00"
@stdin = global i32 0
@stdout = global i32 0
@.str.1 = [3 x i8] c"\08\08\00"
@.str.2 = [4 x i8] c"\08\08\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.spinner*
%7 = alloca [128 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.spinner* (...) @spinner_new()
store %struct.spinner* %9, %struct.spinner** %6
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @stderr
%17 = call i32 @fputs(i8* %15, i32 %16)
br label %18
18: ; preds = %12, %2
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %47, %18
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i64 @fread(i8* %22, i32 1, i32 128, i32 %23)
store i64 %24, i64* %8
%25 = icmp ugt i64 %24, 0
br i1 %25, label %26, label %60
26: ; preds = %21
%27 = load i32, i32* @stdin
%28 = call i64 @ferror(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fputc(i8 signext 10, i32 %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @perror(i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %26
%39 = load i32, i32* @stdin
%40 = call i64 @feof(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = call i32 @fputc(i8 signext 10, i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %38
br label %47
47: ; preds = %46
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%49 = load i64, i64* %8
%50 = load i32, i32* @stdout
%51 = call i32 @fwrite(i8* %48, i32 1, i64 %49, i32 %50)
%52 = load i32, i32* @stderr
%53 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = load %struct.spinner*, %struct.spinner** %6
%55 = call signext i8 @spinner_advance(%struct.spinner* %54)
%56 = load i32, i32* @stderr
%57 = call i32 @fputc(i8 signext %55, i32 %56)
%58 = load i32, i32* @stderr
%59 = call i32 @fputc(i8 signext 32, i32 %58)
br label %21
60: ; preds = %21
%61 = load i32, i32* @stderr
%62 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %61)
ret i32 0
}

LLVM IR (-O2):
%struct.spinner = type { i32 }
@stderr = global i32 0
@.str = [3 x i8] c" \00"
@stdin = global i32 0
@stdout = global i32 0
@.str.1 = [3 x i8] c"\08\08\00"
@.str.2 = [4 x i8] c"\08\08\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = tail call %struct.spinner* (...) @spinner_new()
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* %9, i32 %10)
br label %12
12: ; preds = %7, %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @stdin
%16 = call i64 @fread(i8* %5, i32 1, i32 128, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %50, label %18
18: ; preds = %12, %37
%19 = phi i64 [ %48, %37 ], [ %16, %12 ]
%20 = load i32, i32* @stdin
%21 = call i64 @ferror(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fputc(i8 signext 10, i32 %24)
%26 = load i8*, i8** %1
%27 = call i32 @perror(i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = load i32, i32* @stdin
%31 = call i64 @feof(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fputc(i8 signext 10, i32 %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %29
%38 = load i32, i32* @stdout
%39 = call i32 @fwrite(i8* %5, i32 1, i64 %19, i32 %38)
%40 = load i32, i32* @stderr
%41 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = call signext i8 @spinner_advance(%struct.spinner* %4)
%43 = load i32, i32* @stderr
%44 = call i32 @fputc(i8 signext %42, i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 @fputc(i8 signext 32, i32 %45)
%47 = load i32, i32* @stdin
%48 = call i64 @fread(i8* %5, i32 1, i32 128, i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %18
50: ; preds = %37, %12
%51 = load i32, i32* @stderr
%52 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
ret i32 0
}