#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 INT_MAX;
int convert_time(char const *);
char *format_time(char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
void maybe_sleep(const char *wait_time) {
  char message[80 + 1];
  int int_wait_time;
  int_wait_time = convert_time(wait_time);
  if (int_wait_time > 0) {
    printf("Sleeping for %s\n", format_time(message, wait_time));
    sleep(int_wait_time);
  } else if (int_wait_time == 0) {
    printf("Sleeping forever...CTRL-C exits\n");
    do {
      sleep(INT_MAX);
    } while (1);
  }
}


x86 assembly (clang, -O0):
<maybe_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <convert_time@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jle    118d <maybe_sleep+0x4d>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <format_time@plt>
mov    %rax,%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%edi
call   1060 <sleep@plt>
jmp    11cc <maybe_sleep+0x8c>
cmpl   $0x0,-0x64(%rbp)
jne    11c7 <maybe_sleep+0x87>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1060 <sleep@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11a5 <maybe_sleep+0x65>
jmp    11c2 <maybe_sleep+0x82>
jmp    11c7 <maybe_sleep+0x87>
jmp    11cc <maybe_sleep+0x8c>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maybe_sleep>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
call   1040 <convert_time@plt>
test   %eax,%eax
jle    1189 <maybe_sleep+0x39>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1060 <format_time@plt>
lea    0xe8a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <sleep@plt>
jmp    118b <maybe_sleep+0x3b>
je     1192 <maybe_sleep+0x42>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e43(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%edi
call   1070 <sleep@plt>
jmp    11b0 <maybe_sleep+0x60>

LLVM IR (-O0):
@.str = [17 x i8] c"Sleeping for %s\0A\00"
@.str.1 = [33 x i8] c"Sleeping forever...CTRL-C exits\0A\00"
@INT_MAX = global i32 0
define void @maybe_sleep(i8* %0) {
%2 = alloca i8*
%3 = alloca [81 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @convert_time(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i8* @format_time(i8* %10, i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %4
%15 = call i32 @sleep(i32 %14)
br label %27
16: ; preds = %1
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %24, %19
%22 = load i32, i32* @INT_MAX
%23 = call i32 @sleep(i32 %22)
br label %24
24: ; preds = %21
br i1 true, label %21, label %25
25: ; preds = %24
br label %26
26: ; preds = %25, %16
br label %27
27: ; preds = %26, %9
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Sleeping for %s\0A\00"
@INT_MAX = global i32 0
@str = [32 x i8] c"Sleeping forever...CTRL-C exits\00"
define void @maybe_sleep(i8* %0) {
%2 = alloca [81 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @convert_time(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = call i8* @format_time(i8* %3, i8* %0)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 @sleep(i32 %4)
br label %17
10: ; preds = %1
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %14, %12
%15 = load i32, i32* @INT_MAX
%16 = tail call i32 @sleep(i32 %15)
br label %14
17: ; preds = %10, %6
ret void
}