#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 */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(scalar_t__);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  struct tm *newtime;
  time_t ltime;
  printf("Setting VT terminal clock ...\n");
  time(&ltime);
  newtime = localtime(&ltime);
  printf("Time now: %d:%.2d:%.2d\n", newtime->tm_hour, newtime->tm_min,
         newtime->tm_sec);
  if (newtime->tm_sec != 0) {
    sleep(60 - newtime->tm_sec);
    newtime->tm_min += 1;
  }
  printf("%c[%d;%d,p", 27, newtime->tm_hour, newtime->tm_min);
  printf("Time set to %d:%.2d:00\n", newtime->tm_hour, newtime->tm_min);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x8(%rax)
je     11c4 <main+0x84>
mov    -0x10(%rbp),%rcx
mov    $0x3c,%eax
sub    0x8(%rcx),%eax
movslq %eax,%rdi
call   1060 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
lea    0xe5f(%rip),%rdi
mov    $0x1b,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
mov    (%rax),%esi
mov    0x4(%rax),%edx
mov    0x8(%rax),%ecx
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x8(%rbx),%rax
test   %rax,%rax
je     11b0 <main+0x60>
mov    $0x3c,%edi
sub    %rax,%rdi
call   1070 <sleep@plt>
mov    0x4(%rbx),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rbx)
jmp    11b3 <main+0x63>
mov    0x4(%rbx),%ecx
mov    (%rbx),%edx
lea    0xe5c(%rip),%rdi
mov    $0x1b,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [31 x i8] c"Setting VT terminal clock ...\0A\00"
@.str.1 = [24 x i8] c"Time now: %d:%.2d:%.2d\0A\00"
@.str.2 = [11 x i8] c"%c[%d;%d,p\00"
@.str.3 = [24 x i8] c"Time set to %d:%.2d:00\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @time(i32* %3)
%6 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %6, %struct.tm** %2
%7 = load %struct.tm*, %struct.tm** %2
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.tm*, %struct.tm** %2
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load %struct.tm*, %struct.tm** %2
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %12, i32 %15)
%17 = load %struct.tm*, %struct.tm** %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %0
%22 = load %struct.tm*, %struct.tm** %2
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = sub nsw i32 60, %24
%26 = sext i32 %25 to i64
%27 = call i32 @sleep(i64 %26)
%28 = load %struct.tm*, %struct.tm** %2
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %21, %0
%33 = load %struct.tm*, %struct.tm** %2
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load %struct.tm*, %struct.tm** %2
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 27, i32 %35, i32 %38)
%40 = load %struct.tm*, %struct.tm** %2
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load %struct.tm*, %struct.tm** %2
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %45)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str.1 = [24 x i8] c"Time now: %d:%.2d:%.2d\0A\00"
@.str.2 = [11 x i8] c"%c[%d;%d,p\00"
@.str.3 = [24 x i8] c"Time set to %d:%.2d:00\0A\00"
@str = [30 x i8] c"Setting VT terminal clock ...\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = call i32 @time(i32* %1)
%5 = call %struct.tm* @localtime(i32* %1)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9, i32 %11)
%13 = load i32, i32* %10
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = load i32, i32* %8
br label %23
17: ; preds = %0
%18 = sub nsw i32 60, %13
%19 = sext i32 %18 to i64
%20 = call i32 @sleep(i64 %19)
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %23
23: ; preds = %15, %17
%24 = phi i32 [ %16, %15 ], [ %22, %17 ]
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 27, i32 %25, i32 %24)
%27 = load i32, i32* %6
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
ret i32 0
}