#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 EOF;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(unsigned int);
int sscanf(char const *, char *, unsigned int *, char);
void do_sleep(const char *arg) {
  char unit_char;
  unsigned int timeunits;
  unsigned int seconds = 0;
  int ret = sscanf(arg, "%u%c", &timeunits, unit_char);
  if (ret == EOF || ret == 0) {
    print_help();
    return;
  }
  if (unit_char == 's' || ret == 1) {
    seconds = timeunits;
  } else if (unit_char == 'm') {
    seconds = timeunits * 60;
  } else if (unit_char == 'h') {
    seconds = timeunits * 3600;
  } else if (unit_char == 'd') {
    seconds = timeunits * 86400;
  } else {
    printf("sleep - invalid time suffix\n");
    print_help();
    return;
  }
  sleep(seconds);
}


x86 assembly (clang, -O0):
<do_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
lea    -0x10(%rbp),%rdx
movsbl -0x9(%rbp),%ecx
call   1040 <sscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
je     118a <do_sleep+0x4a>
cmpl   $0x0,-0x18(%rbp)
jne    1196 <do_sleep+0x56>
mov    $0x0,%al
call   1050 <print_help@plt>
jmp    1238 <do_sleep+0xf8>
movsbl -0x9(%rbp),%eax
cmp    $0x73,%eax
je     11ad <do_sleep+0x6d>
cmpl   $0x1,-0x18(%rbp)
jne    11b8 <do_sleep+0x78>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1230 <do_sleep+0xf0>
movsbl -0x9(%rbp),%eax
cmp    $0x6d,%eax
jne    11d1 <do_sleep+0x91>
imul   $0x3c,-0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122b <do_sleep+0xeb>
movsbl -0x9(%rbp),%eax
cmp    $0x68,%eax
jne    11ed <do_sleep+0xad>
imul   $0xe10,-0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1226 <do_sleep+0xe6>
movsbl -0x9(%rbp),%eax
cmp    $0x64,%eax
jne    1209 <do_sleep+0xc9>
imul   $0x15180,-0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1221 <do_sleep+0xe1>
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <print_help@plt>
jmp    1238 <do_sleep+0xf8>
jmp    1226 <do_sleep+0xe6>
jmp    122b <do_sleep+0xeb>
jmp    1230 <do_sleep+0xf0>
mov    -0x14(%rbp),%edi
call   1060 <sleep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_sleep>:
push   %rax
lea    0xeb8(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %ecx,%ecx
call   1040 <sscanf@plt>
test   %eax,%eax
je     117f <do_sleep+0x3f>
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%eax
je     117f <do_sleep+0x3f>
cmp    $0x1,%eax
jne    1173 <do_sleep+0x33>
mov    0x4(%rsp),%edi
call   1060 <sleep@plt>
pop    %rax
ret
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <print_help@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%u%c\00"
@EOF = global i32 0
@.str.1 = [29 x i8] c"sleep - invalid time suffix\0A\00"
define void @do_sleep(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = load i8, i8* %3
%9 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4, i8 signext %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13, %1
%17 = call i32 (...) @print_help()
br label %57
18: ; preds = %13
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 115
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %22, %18
%26 = load i32, i32* %4
store i32 %26, i32* %5
br label %54
27: ; preds = %22
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 109
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %4
%33 = mul i32 %32, 60
store i32 %33, i32* %5
br label %53
34: ; preds = %27
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 104
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %4
%40 = mul i32 %39, 3600
store i32 %40, i32* %5
br label %52
41: ; preds = %34
%42 = load i8, i8* %3
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 100
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %4
%47 = mul i32 %46, 86400
store i32 %47, i32* %5
br label %51
48: ; preds = %41
%49 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 (...) @print_help()
br label %57
51: ; preds = %45
br label %52
52: ; preds = %51, %38
br label %53
53: ; preds = %52, %31
br label %54
54: ; preds = %53, %25
%55 = load i32, i32* %5
%56 = call i32 @sleep(i32 %55)
br label %57
57: ; preds = %54, %48, %16
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%u%c\00"
@EOF = global i32 0
@str = [28 x i8] c"sleep - invalid time suffix\00"
define void @do_sleep(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i8 signext undef)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
%7 = icmp eq i32 %4, 0
%8 = or i1 %7, %6
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (...) @print_help()
br label %19
11: ; preds = %1
%12 = icmp eq i32 %4, 1
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%15 = call i32 (...) @print_help()
br label %19
16: ; preds = %11
%17 = load i32, i32* %2
%18 = call i32 @sleep(i32 %17)
br label %19
19: ; preds = %16, %13, %9
ret void
}