#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 int /*<<< orphan*/ time_t;
struct tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ fatal(char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int number_of_columns();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(long);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd;
  int cols = number_of_columns();
  time_t tid;
  struct tm *t;
  char tijd[10];
  if ((fd = open("/dev/vcs", O_WRONLY)) < 0 &&
      (fd = open("/dev/vcs0", O_WRONLY)) < 0)
    fatal("/dev/vcs");
  while (1) {
    lseek(fd, cols - 10, 0);
    tid = time(0);
    t = localtime(&tid);
    sprintf(tijd, " %02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
    write(fd, tijd, 9);
    usleep(500000L);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <number_of_columns@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11f7 <main+0x67>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11f7 <main+0x67>
lea    0xe0e(%rip),%rdi
call   10a0 <fatal@plt>
jmp    11fc <main+0x6c>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0xa,%esi
mov    %esi,-0x28(%rbp)
xor    %edx,%edx
call   1060 <lseek@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xdcd(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
jmp    11fc <main+0x6c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <number_of_columns@plt>
mov    %eax,%r12d
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%esi
lea    0xe4a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11e1 <main+0x51>
mov    (%rbx),%esi
lea    0xe3f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11e1 <main+0x51>
lea    0xe24(%rip),%rdi
call   10a0 <fatal@plt>
add    $0xfffffff6,%r12d
mov    %rsp,%r14
lea    0xe24(%rip),%r15
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r12d,%esi
xor    %edx,%edx
call   1060 <lseek@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,(%rsp)
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <sprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1040 <write@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
jmp    1200 <main+0x70>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [9 x i8] c"/dev/vcs\00"
@O_WRONLY = global i32 0
@.str.1 = [10 x i8] c"/dev/vcs0\00"
@.str.2 = [16 x i8] c" %02d:%02d:%02d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca [10 x i8]
store i32 0, i32* %1
%7 = call i32 (...) @number_of_columns()
store i32 %7, i32* %3
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @fatal(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11, %0
br label %18
18: ; preds = %17, %18
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 10
%22 = call i32 @lseek(i32 %19, i32 %21, i32 0)
%23 = call i32 @time(i32 0)
store i32 %23, i32* %4
%24 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %24, %struct.tm** %5
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%26 = load %struct.tm*, %struct.tm** %5
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load %struct.tm*, %struct.tm** %5
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = load %struct.tm*, %struct.tm** %5
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %31, i32 %34)
%36 = load i32, i32* %2
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%38 = call i32 @write(i32 %36, i8* %37, i32 9)
%39 = call i32 @usleep(i64 500000)
br label %18
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [9 x i8] c"/dev/vcs\00"
@O_WRONLY = global i32 0
@.str.1 = [10 x i8] c"/dev/vcs0\00"
@.str.2 = [16 x i8] c" %02d:%02d:%02d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = tail call i32 (...) @number_of_columns()
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @O_WRONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fatal(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9, %0
%16 = phi i32 [ %11, %13 ], [ %11, %9 ], [ %7, %0 ]
%17 = add nsw i32 %3, -10
br label %18
18: ; preds = %18, %15
%19 = call i32 @lseek(i32 %16, i32 %17, i32 0)
%20 = call i32 @time(i32 0)
store i32 %20, i32* %1
%21 = call %struct.tm* @localtime(i32* %1)
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i64 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %21, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %21, i64 0, i32 2
%27 = load i32, i32* %26
%28 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %25, i32 %27)
%29 = call i32 @write(i32 %16, i8* %5, i32 9)
%30 = call i32 @usleep(i64 500000)
br label %18
}