#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int, int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int sched_getcpu();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int cpu;
  int previous = -1;
  time_t now;
  struct tm *now_tm;
  for (;;) {
    cpu = sched_getcpu();
    if (cpu == -1) {
      perror("sched_getcpu");
      exit(EXIT_FAILURE);
    }
    if (previous == -1)
      previous = cpu;
    if (cpu != previous) {
      now = time(NULL);
      now_tm = localtime(&now);
      fprintf(stdout, "%02d:%02d:%02d migration %d -> %d\n", now_tm->tm_hour,
              now_tm->tm_min, now_tm->tm_sec, previous, cpu);
      previous = cpu;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    $0x0,%al
call   1070 <sched_getcpu@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a4 <main+0x44>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b4 <main+0x54>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1213 <main+0xb3>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0xc(%rbp),%r9d
mov    -0x8(%rbp),%eax
lea    0xe08(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <sched_getcpu@plt>
cmp    $0xffffffff,%eax
jne    1192 <main+0x32>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0xffffffff,%ebx
lea    0xc(%rsp),%r14
mov    0x2e35(%rip),%r12
lea    0xe63(%rip),%r15
jmp    11bc <main+0x5c>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <sched_getcpu@plt>
cmp    $0xffffffff,%eax
je     1178 <main+0x18>
mov    %ebx,%ebp
mov    %eax,%ebx
cmp    $0xffffffff,%ebp
cmove  %eax,%ebp
cmp    %ebp,%eax
je     11b0 <main+0x50>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    (%r12),%edi
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
mov    %ebx,(%rsp)
mov    %r15,%rsi
mov    %ebp,%r9d
call   1040 <fprintf@plt>
jmp    11b0 <main+0x50>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [13 x i8] c"sched_getcpu\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [35 x i8] c"%02d:%02d:%02d migration %d -> %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.tm*
store i32 0, i32* %1
store i32 -1, i32* %3
br label %6
6: ; preds = %40, %0
%7 = call i32 (...) @sched_getcpu()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %6
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32, i32* %2
store i32 %18, i32* %3
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = call i32 @time(i32* null)
store i32 %24, i32* %4
%25 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %25, %struct.tm** %5
%26 = load i32, i32* @stdout
%27 = load %struct.tm*, %struct.tm** %5
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load %struct.tm*, %struct.tm** %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load %struct.tm*, %struct.tm** %5
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = load i32, i32* %3
%37 = load i32, i32* %2
%38 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %32, i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %2
store i32 %39, i32* %3
br label %40
40: ; preds = %23, %19
br label %6
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [13 x i8] c"sched_getcpu\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [35 x i8] c"%02d:%02d:%02d migration %d -> %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (...) @sched_getcpu()
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %26, %0
%6 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0, %26
%10 = phi i32 [ %27, %26 ], [ %3, %0 ]
%11 = phi i32 [ %10, %26 ], [ -1, %0 ]
%12 = icmp eq i32 %11, -1
%13 = select i1 %12, i32 %10, i32 %11
%14 = icmp eq i32 %10, %13
br i1 %14, label %26, label %15
15: ; preds = %9
%16 = call i32 @time(i32* null)
store i32 %16, i32* %1
%17 = call %struct.tm* @localtime(i32* %1)
%18 = load i32, i32* @stdout
%19 = getelementptr inbounds %struct.tm, %struct.tm* %17, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %17, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %17, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %13, i32 %10)
br label %26
26: ; preds = %15, %9
%27 = call i32 (...) @sched_getcpu()
%28 = icmp eq i32 %27, -1
br i1 %28, label %5, label %9
}