#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main() {
  int i = 0;
  printf("Demo is running\n");
  while (i < 10) {
    i = i + 1;
    sleep(1);
    printf("Demo has running %d seconds.\n", i);
    fflush(stdout);
  }
  printf("Demo is ending.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xa,-0x8(%rbp)
jge    1195 <main+0x65>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x8(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
jmp    1154 <main+0x24>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e69(%rip),%rbx
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xd89(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Demo is running\0A\00"
@.str.1 = [30 x i8] c"Demo has running %d seconds.\0A\00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"Demo is ending.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %7, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = call i32 @sleep(i32 1)
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
br label %4
15: ; preds = %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Demo has running %d seconds.\0A\00"
@stdout = global i32 0
@str = [16 x i8] c"Demo is running\00"
@str.3 = [16 x i8] c"Demo is ending.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @sleep(i32 1)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 2)
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 3)
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 4)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 5)
%20 = load i32, i32* @stdout
%21 = tail call i32 @fflush(i32 %20)
%22 = tail call i32 @sleep(i32 1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 6)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
%26 = tail call i32 @sleep(i32 1)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 7)
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
%30 = tail call i32 @sleep(i32 1)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 8)
%32 = load i32, i32* @stdout
%33 = tail call i32 @fflush(i32 %32)
%34 = tail call i32 @sleep(i32 1)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 9)
%36 = load i32, i32* @stdout
%37 = tail call i32 @fflush(i32 %36)
%38 = tail call i32 @sleep(i32 1)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 10)
%40 = load i32, i32* @stdout
%41 = tail call i32 @fflush(i32 %40)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}