#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 scalar_t__ time_t;
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ gauge_print(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(scalar_t__ *);
int /*<<< orphan*/ poll(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  int cnt;
  char buf[1024];
  struct timeval start_time;
  struct timeval end_time;
  struct timeval diff_time;
  time_t diff_tm;
  gettimeofday(&start_time, NULL);
  printf("\n+------------------------------------+\n");
  printf("| GAUGE PRINT EXAMPLE                |\n");
  printf("+------------------------------------+\n\n");
  printf("\n\n|0----------25-----------50----------75---------100|\n");
  cnt = 100;
  for (i = cnt; i < 1000; i++) {
    gauge_print(i, cnt);
    poll(0, 0, 1);
  }
  printf("****************************************************\n");
  gettimeofday(&end_time, NULL);
  diff_tm = end_time.tv_sec - start_time.tv_sec;
  diff_time.tv_usec = end_time.tv_usec - start_time.tv_usec;
  if (diff_time.tv_usec < 0) {
    diff_time.tv_usec += 1000000;
  }
  diff_time.tv_usec = diff_time.tv_usec / 1000;
  strftime(buf, sizeof(buf), "%M:%S.", localtime(&diff_tm));
  printf("Elapsed time : %s%03d\n\n", buf, diff_time.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x430(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x64,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1202 <main+0xa2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <gauge_print@plt>
xor    %esi,%esi
mov    $0x1,%edx
mov    %esi,%edi
call   1070 <poll@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ce <main+0x6e>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x440(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x438(%rbp),%rax
sub    -0x428(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x440(%rbp),%eax
sub    -0x430(%rbp),%eax
mov    %eax,-0x450(%rbp)
cmpl   $0x0,-0x450(%rbp)
jge    1265 <main+0x105>
mov    -0x450(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x450(%rbp)
mov    -0x450(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x450(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x460(%rbp)
lea    -0x458(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x460(%rbp),%rdi
mov    %eax,%ecx
mov    $0x400,%esi
lea    0xe40(%rip),%rdx
call   1080 <strftime@plt>
lea    -0x420(%rbp),%rsi
mov    -0x450(%rbp),%edx
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x438,%rsp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x64,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x64,%esi
call   1050 <gauge_print@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <poll@plt>
add    $0x1,%ebx
cmp    $0x3e8,%ebx
jne    11c0 <main+0x50>
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x18(%rsp),%rax
sub    0x28(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x10(%rsp),%eax
sub    0x20(%rsp),%eax
lea    0xf4240(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xdb9(%rip),%rdx
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
lea    0xda5(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [41 x i8] c"\0A+------------------------------------+\0A\00"
@.str.1 = [40 x i8] c"| GAUGE PRINT EXAMPLE |\0A\00"
@.str.2 = [41 x i8] c"+------------------------------------+\0A\0A\00"
@.str.3 = [56 x i8] c"\0A\0A|0----------25-----------50----------75---------100|\0A\00"
@.str.4 = [54 x i8] c"****************************************************\0A\00"
@.str.5 = [7 x i8] c"%M:%S.\00"
@.str.6 = [24 x i8] c"Elapsed time : %s%03d\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
store i32 100, i32* %7
%18 = load i32, i32* %7
store i32 %18, i32* %6
br label %19
19: ; preds = %27, %2
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 1000
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @gauge_print(i32 %23, i32 %24)
%26 = call i32 @poll(i32 0, i32 0, i32 1)
br label %27
27: ; preds = %22
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %19
30: ; preds = %19
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%36 = load i64, i64* %35
%37 = sub nsw i64 %34, %36
store i64 %37, i64* %12
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%41 = load i32, i32* %40
%42 = sub nsw i32 %39, %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%45 = load i32, i32* %44
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %30
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%49 = load i32, i32* %48
%50 = add nsw i32 %49, 1000000
store i32 %50, i32* %48
br label %51
51: ; preds = %47, %30
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sdiv i32 %53, 1000
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 %54, i32* %55
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%57 = call i32 @localtime(i64* %12)
%58 = call i32 @strftime(i8* %56, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %59, i32 %61)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str.5 = [7 x i8] c"%M:%S.\00"
@.str.6 = [24 x i8] c"Elapsed time : %s%03d\0A\0A\00"
@str = [40 x i8] c"\0A+------------------------------------+\00"
@str.7 = [39 x i8] c"| GAUGE PRINT EXAMPLE |\00"
@str.8 = [40 x i8] c"+------------------------------------+\0A\00"
@str.9 = [55 x i8] c"\0A\0A|0----------25-----------50----------75---------100|\00"
@str.10 = [53 x i8] c"****************************************************\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.timeval* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.7, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.9, i64 0, i64 0))
br label %16
16: ; preds = %2, %16
%17 = phi i32 [ 100, %2 ], [ %20, %16 ]
%18 = tail call i32 @gauge_print(i32 %17, i32 100)
%19 = tail call i32 @poll(i32 0, i32 0, i32 1)
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, 1000
br i1 %21, label %22, label %16
22: ; preds = %16
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0))
%24 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%28 = load i64, i64* %27
%29 = sub nsw i64 %26, %28
store i64 %29, i64* %6
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%33 = load i32, i32* %32
%34 = sub nsw i32 %31, %33
%35 = icmp slt i32 %34, 0
%36 = add nsw i32 %34, 1000000
%37 = select i1 %35, i32 %36, i32 %34
%38 = sdiv i32 %37, 1000
%39 = call i32 @localtime(i64* %6)
%40 = call i32 @strftime(i8* %7, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %7, i32 %38)
ret i32 0
}