#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*/ LOG(char *, int /*<<< orphan*/);
scalar_t__ nightyNight();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ timestamp();
int goToSleep() {
  LOG("%s Going to sleep\n", timestamp());
  if (nightyNight()) {
    LOG("%s Failed to go to sleep\n", timestamp());
    return -1;
  }
  sleep(10);
  sleep(10);
  LOG("%s Woke up from sleep\n", timestamp());
  return 0;
}


x86 assembly (clang, -O0):
<goToSleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <timestamp@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
call   1050 <LOG@plt>
mov    $0x0,%al
call   1040 <nightyNight@plt>
cmp    $0x0,%rax
je     118f <goToSleep+0x4f>
mov    $0x0,%al
call   1030 <timestamp@plt>
mov    %eax,%esi
lea    0xe95(%rip),%rdi
call   1050 <LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <goToSleep+0x7f>
mov    $0xa,%edi
call   1060 <sleep@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <timestamp@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
call   1050 <LOG@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goToSleep>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <timestamp@plt>
lea    0xead(%rip),%rdi
mov    %eax,%esi
call   1050 <LOG@plt>
xor    %eax,%eax
call   1040 <nightyNight@plt>
test   %rax,%rax
je     1174 <goToSleep+0x34>
mov    $0xffffffff,%ebp
lea    0xea1(%rip),%rbx
jmp    118f <goToSleep+0x4f>
mov    $0xa,%edi
call   1060 <sleep@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
lea    0xe9e(%rip),%rbx
xor    %eax,%eax
call   1030 <timestamp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <LOG@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%s Going to sleep\0A\00"
@.str.1 = [26 x i8] c"%s Failed to go to sleep\0A\00"
@.str.2 = [23 x i8] c"%s Woke up from sleep\0A\00"
define i32 @goToSleep() {
%1 = alloca i32
%2 = call i32 (...) @timestamp()
%3 = call i32 @LOG(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = call i64 (...) @nightyNight()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (...) @timestamp()
%8 = call i32 @LOG(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 -1, i32* %1
br label %14
9: ; preds = %0
%10 = call i32 @sleep(i32 10)
%11 = call i32 @sleep(i32 10)
%12 = call i32 (...) @timestamp()
%13 = call i32 @LOG(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 0, i32* %1
br label %14
14: ; preds = %9, %6
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s Going to sleep\0A\00"
@.str.1 = [26 x i8] c"%s Failed to go to sleep\0A\00"
@.str.2 = [23 x i8] c"%s Woke up from sleep\0A\00"
define i32 @goToSleep() {
%1 = tail call i32 (...) @timestamp()
%2 = tail call i32 @LOG(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i64 (...) @nightyNight()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @sleep(i32 10)
%7 = tail call i32 @sleep(i32 10)
br label %8
8: ; preds = %0, %5
%9 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %0 ]
%10 = phi i32 [ 0, %5 ], [ -1, %0 ]
%11 = tail call i32 (...) @timestamp()
%12 = tail call i32 @LOG(i8* %9, i32 %11)
ret i32 %10
}