#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 winsize {
  int ws_col;
};
typedef int /*<<< orphan*/ bar;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int i = 0;
  char bar[1024];
  char str[] = "|\\-/";
  struct winsize w;
  memset(bar, 0, sizeof(bar));
  ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
  for (i = 0; i < w.ws_col - 2; i++) {
    bar[i] = '#';
    printf("[%-104s][%d%%][%c]\r", bar, i, str[i % 4]);
    fflush(stdout);
    usleep(100000);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe8a(%rip),%eax
mov    %eax,-0x425(%rbp)
mov    0xe82(%rip),%al
mov    %al,-0x421(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x430(%rbp),%rdx
call   1050 <ioctl@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x430(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1241 <main+0xf1>
movslq -0x14(%rbp),%rax
movb   $0x23,-0x420(%rbp,%rax,1)
23
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x434(%rbp),%edx
cltq
movsbl -0x425(%rbp,%rax,1),%ecx
ff
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <main+0x70>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1060 <ioctl@plt>
cmpl   $0x3,0x8(%rsp)
jl     1203 <main+0xa3>
lea    0xe55(%rip),%r12
lea    0xe53(%rip),%r14
lea    0x10(%rsp),%r15
mov    0x2e1a(%rip),%r13
xor    %ebx,%ebx
movb   $0x23,0x10(%rsp,%rbx,1)
mov    %ebx,%eax
and    $0x3,%eax
movsbl (%rax,%r12,1),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0xfffffffffffffffe,%rax
cmp    %rax,%rbx
jl     11c0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.winsize = type { i32 }
@__const.main.str = [5 x i8] c"|\\-/\00"
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [20 x i8] c"[%-104s][%d%%][%c]\0D\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [5 x i8]
%9 = alloca %struct.winsize
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = bitcast [5 x i8]* %8 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1024)
%13 = load i32, i32* @STDOUT_FILENO
%14 = load i32, i32* @TIOCGWINSZ
%15 = call i32 @ioctl(i32 %13, i32 %14, %struct.winsize* %9)
store i32 0, i32* %6
br label %16
16: ; preds = %38, %2
%17 = load i32, i32* %6
%18 = getelementptr inbounds %struct.winsize, %struct.winsize* %9, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, 2
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %41
22: ; preds = %16
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %24
store i8 35, i8* %25
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %6
%28 = load i32, i32* %6
%29 = srem i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27, i32 %33)
%35 = load i32, i32* @stdout
%36 = call i32 @fflush(i32 %35)
%37 = call i32 @usleep(i32 100000)
br label %38
38: ; preds = %22
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %16
41: ; preds = %16
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.winsize = type { i32 }
@__const.main.str = [5 x i8] c"|\\-/\00"
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [20 x i8] c"[%-104s][%d%%][%c]\0D\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.winsize
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.winsize* %4 to i8*
%7 = call i32 @memset(i8* %5, i32 0, i32 1024)
%8 = load i32, i32* @STDOUT_FILENO
%9 = load i32, i32* @TIOCGWINSZ
%10 = call i32 @ioctl(i32 %8, i32 %9, %struct.winsize* %4)
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %31
14: ; preds = %2, %14
%15 = phi i64 [ %26, %14 ], [ 0, %2 ]
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %15
store i8 35, i8* %16
%17 = trunc i64 %15 to i32
%18 = and i64 %15, 3
%19 = getelementptr inbounds [5 x i8], [5 x i8]* @__const.main.str, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %17, i32 %21)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = call i32 @usleep(i32 100000)
%26 = add nuw nsw i64 %15, 1
%27 = load i32, i32* %11
%28 = add nsw i32 %27, -2
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %26, %29
br i1 %30, label %14, label %31
31: ; preds = %14, %2
%32 = call i32 @putchar(i32 10)
ret i32 0
}