#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int random();
int /*<<< orphan*/ sleep(unsigned int);
int /*<<< orphan*/ srandomdev();
int main(int argc, char *argv[]) {
  int error;
  unsigned int maxsleepsecs;
  unsigned int sleepsecs;
  if (argc != 2) {
    printf("usage: %s maxsleepsecs\n", argv[0]);
    exit(1);
  }
  if ((maxsleepsecs = atoi(argv[1]))) {
    if (maxsleepsecs > 315532800) {
      printf("I refuse to sleep for a year.\n");
      exit(2);
    }
  } else {
    printf("Error. Not a number.\n");
    exit(3);
  }
  srandomdev();
  sleepsecs = (random() % maxsleepsecs) + 1;
  sleep(sleepsecs);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11db <main+0x7b>
cmpl   $0x12cea600,-0x18(%rbp)
jbe    11d6 <main+0x76>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    11f3 <main+0x93>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1050 <srandomdev@plt>
mov    $0x0,%al
call   1040 <random@plt>
xor    %edx,%edx
divl   -0x18(%rbp)
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11aa <main+0x3a>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     11c5 <main+0x55>
mov    %eax,%ebx
cmp    $0x12cea601,%eax
jae    11db <main+0x6b>
xor    %eax,%eax
call   1060 <srandomdev@plt>
xor    %eax,%eax
call   1050 <random@plt>
xor    %edx,%edx
div    %ebx
lea    0x1(%rdx),%edi
call   1090 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"usage: %s maxsleepsecs\0A\00"
@.str.1 = [31 x i8] c"I refuse to sleep for a year.\0A\00"
@.str.2 = [22 x i8] c"Error. Not a number.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = load i32, i32* %6
%24 = icmp ugt i32 %23, 315532800
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %22
br label %32
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 3)
unreachable
32: ; preds = %28
%33 = call i32 (...) @srandomdev()
%34 = call i32 (...) @random()
%35 = load i32, i32* %6
%36 = urem i32 %34, %35
%37 = add i32 %36, 1
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = call i32 @sleep(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"usage: %s maxsleepsecs\0A\00"
@str = [21 x i8] c"Error. Not a number.\00"
@str.3 = [30 x i8] c"I refuse to sleep for a year.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = icmp ugt i32 %11, 315532800
br i1 %14, label %15, label %21
15: ; preds = %13
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0))
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %8
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 3)
unreachable
21: ; preds = %13
%22 = tail call i32 (...) @srandomdev()
%23 = tail call i32 (...) @random()
%24 = urem i32 %23, %11
%25 = add nuw nsw i32 %24, 1
%26 = tail call i32 @sleep(i32 %25)
ret i32 0
}