#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 u_int;
typedef int time_t;
typedef int /*<<< orphan*/ tb;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ localtime(int *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int *);
int write(int /*<<< orphan*/, char *, int);
void doalarm(u_int secs) {
  int bother;
  time_t daytime;
  char tb[80];
  int pid;
  if ((pid = fork())) {
    (void)time(&daytime);
    daytime += secs;
    strftime(tb, sizeof(tb), "%+", localtime(&daytime));
    printf("Alarm set for %s. (pid %d)\n", tb, pid);
    exit(0);
  }
  sleep((u_int)2);
  if (secs >= 2)
    secs -= 2;
  if (secs >= (5 * 60)) {
    sleep(secs - (5 * 60));
    if (write(STDOUT_FILENO, "\07\07You have to leave in 5 minutes.\n",
              sizeof("\07\07You have to leave in 5 minutes.\n") - 1) !=
        sizeof("\07\07You have to leave in 5 minutes.\n") - 1)
      exit(0);
    secs = (5 * 60);
  }
  if (secs >= (60)) {
    sleep(secs - (60));
    if (write(STDOUT_FILENO, "\07\07Just one more minute!\n",
              sizeof("\07\07Just one more minute!\n") - 1) !=
        sizeof("\07\07Just one more minute!\n") - 1)
      exit(0);
  }
  for (bother = 10; bother--;) {
    sleep((u_int)(60));
    if (write(STDOUT_FILENO, "\07\07Time to leave!\n",
              sizeof("\07\07Time to leave!\n") - 1) !=
        sizeof("\07\07Time to leave!\n") - 1)
      exit(0);
  }
  (void)write(
      STDOUT_FILENO, "\07\07That was the last time I'll tell you.  Bye.\n",
      sizeof("\07\07That was the last time I'll tell you.  Bye.\n") - 1);
  exit(0);
}


x86 assembly (clang, -O0):
<doalarm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
je     11f2 <doalarm+0x72>
lea    -0xc(%rbp),%rdi
call   1060 <time@plt>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%ecx
mov    $0x50,%esi
lea    0xe2d(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
cmpl   $0x2,-0x4(%rbp)
jl     120f <doalarm+0x8f>
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x12c,-0x4(%rbp)
jl     125e <doalarm+0xde>
mov    -0x4(%rbp),%edi
sub    $0x12c,%edi
call   1090 <sleep@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
cltq
cmp    $0x22,%rax
je     1257 <doalarm+0xd7>
xor    %edi,%edi
call   1080 <exit@plt>
movl   $0x12c,-0x4(%rbp)
cmpl   $0x3c,-0x4(%rbp)
jl     12a5 <doalarm+0x125>
mov    -0x4(%rbp),%edi
sub    $0x3c,%edi
call   1090 <sleep@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
cltq
cmp    $0x18,%rax
je     12a0 <doalarm+0x120>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    12a5 <doalarm+0x125>
movl   $0xa,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     12fc <doalarm+0x17c>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cltq
cmp    $0x11,%rax
je     12f7 <doalarm+0x177>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    12ac <doalarm+0x12c>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
mov    $0x2e,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<doalarm>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jne    11ea <doalarm+0x6a>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    -0x2(%rbx),%edi
cmp    $0x2,%ebx
cmovl  %ebx,%edi
cmp    $0x12c,%edi
jl     1238 <doalarm+0xb8>
add    $0xfffffed4,%edi
call   1090 <sleep@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
mov    $0x12c,%edi
cmp    $0x22,%eax
je     123d <doalarm+0xbd>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1060 <time@plt>
add    %ebx,0xc(%rsp)
mov    %r14,%rdi
call   1030 <localtime@plt>
lea    0xdf4(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %eax,%ecx
call   1070 <strftime@plt>
lea    0xddc(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
cmp    $0x3c,%edi
jl     1268 <doalarm+0xe8>
add    $0xffffffc4,%edi
call   1090 <sleep@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
cmp    $0x18,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    0x2d77(%rip),%rbx
mov    (%rbx),%edi
lea    0xdd9(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xdb3(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xd8d(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xd67(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xd41(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xd1b(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xcf5(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xccf(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xca9(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    $0x3c,%edi
call   1090 <sleep@plt>
mov    (%rbx),%edi
lea    0xc83(%rip),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0x11,%eax
jne    11e3 <doalarm+0x63>
mov    (%rbx),%edi
lea    0xc79(%rip),%rsi
mov    $0x2e,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%+\00"
@.str.1 = [28 x i8] c"Alarm set for %s. (pid %d)\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [35 x i8] c"\07\07You have to leave in 5 minutes.\0A\00"
@.str.3 = [25 x i8] c"\07\07Just one more minute!\0A\00"
@.str.4 = [18 x i8] c"\07\07Time to leave!\0A\00"
@.str.5 = [47 x i8] c"\07\07That was the last time I'll tell you. Bye.\0A\00"
define void @doalarm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = call i32 @time(i32* %4)
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = add nsw i32 %12, %11
store i32 %13, i32* %4
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%15 = call i32 @localtime(i32* %4)
%16 = call i32 @strftime(i8* %14, i32 80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %1
%22 = call i32 @sleep(i32 2)
%23 = load i32, i32* %2
%24 = icmp sge i32 %23, 2
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %2
%27 = sub nsw i32 %26, 2
store i32 %27, i32* %2
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %2
%30 = icmp sge i32 %29, 300
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = load i32, i32* %2
%33 = sub nsw i32 %32, 300
%34 = call i32 @sleep(i32 %33)
%35 = load i32, i32* @STDOUT_FILENO
%36 = call i32 @write(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 34)
%37 = sext i32 %36 to i64
%38 = icmp ne i64 %37, 34
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %31
store i32 300, i32* %2
br label %42
42: ; preds = %41, %28
%43 = load i32, i32* %2
%44 = icmp sge i32 %43, 60
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32, i32* %2
%47 = sub nsw i32 %46, 60
%48 = call i32 @sleep(i32 %47)
%49 = load i32, i32* @STDOUT_FILENO
%50 = call i32 @write(i32 %49, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 24)
%51 = sext i32 %50 to i64
%52 = icmp ne i64 %51, 24
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %45
br label %56
56: ; preds = %55, %42
store i32 10, i32* %3
br label %57
57: ; preds = %69, %56
%58 = load i32, i32* %3
%59 = add nsw i32 %58, -1
store i32 %59, i32* %3
%60 = icmp ne i32 %58, 0
br i1 %60, label %61, label %70
61: ; preds = %57
%62 = call i32 @sleep(i32 60)
%63 = load i32, i32* @STDOUT_FILENO
%64 = call i32 @write(i32 %63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%65 = sext i32 %64 to i64
%66 = icmp ne i64 %65, 17
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %61
br label %57
70: ; preds = %57
%71 = load i32, i32* @STDOUT_FILENO
%72 = call i32 @write(i32 %71, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 46)
%73 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"%+\00"
@.str.1 = [28 x i8] c"Alarm set for %s. (pid %d)\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [35 x i8] c"\07\07You have to leave in 5 minutes.\0A\00"
@.str.3 = [25 x i8] c"\07\07Just one more minute!\0A\00"
@.str.4 = [18 x i8] c"\07\07Time to leave!\0A\00"
@.str.5 = [47 x i8] c"\07\07That was the last time I'll tell you. Bye.\0A\00"
define void @doalarm(i32 %0) {
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = call i32 @time(i32* %2)
%10 = load i32, i32* %2
%11 = add nsw i32 %10, %0
store i32 %11, i32* %2
%12 = call i32 @localtime(i32* %2)
%13 = call i32 @strftime(i8* %5, i32 80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %6)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %1
%17 = tail call i32 @sleep(i32 2)
%18 = icmp sgt i32 %0, 1
%19 = add nsw i32 %0, -2
%20 = select i1 %18, i32 %19, i32 %0
%21 = icmp sgt i32 %20, 299
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = add nsw i32 %20, -300
%24 = tail call i32 @sleep(i32 %23)
%25 = load i32, i32* @STDOUT_FILENO
%26 = tail call i32 @write(i32 %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 34)
%27 = icmp eq i32 %26, 34
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %16
%31 = icmp sgt i32 %20, 59
br i1 %31, label %32, label %41
32: ; preds = %22, %30
%33 = phi i32 [ %20, %30 ], [ 300, %22 ]
%34 = add nsw i32 %33, -60
%35 = tail call i32 @sleep(i32 %34)
%36 = load i32, i32* @STDOUT_FILENO
%37 = tail call i32 @write(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 24)
%38 = icmp eq i32 %37, 24
br i1 %38, label %41, label %39
39: ; preds = %32
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %32, %30
%42 = tail call i32 @sleep(i32 60)
%43 = load i32, i32* @STDOUT_FILENO
%44 = tail call i32 @write(i32 %43, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%45 = icmp eq i32 %44, 17
br i1 %45, label %46, label %91
46: ; preds = %41
%47 = tail call i32 @sleep(i32 60)
%48 = load i32, i32* @STDOUT_FILENO
%49 = tail call i32 @write(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%50 = icmp eq i32 %49, 17
br i1 %50, label %51, label %91
51: ; preds = %46
%52 = tail call i32 @sleep(i32 60)
%53 = load i32, i32* @STDOUT_FILENO
%54 = tail call i32 @write(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%55 = icmp eq i32 %54, 17
br i1 %55, label %56, label %91
56: ; preds = %51
%57 = tail call i32 @sleep(i32 60)
%58 = load i32, i32* @STDOUT_FILENO
%59 = tail call i32 @write(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%60 = icmp eq i32 %59, 17
br i1 %60, label %61, label %91
61: ; preds = %56
%62 = tail call i32 @sleep(i32 60)
%63 = load i32, i32* @STDOUT_FILENO
%64 = tail call i32 @write(i32 %63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%65 = icmp eq i32 %64, 17
br i1 %65, label %66, label %91
66: ; preds = %61
%67 = tail call i32 @sleep(i32 60)
%68 = load i32, i32* @STDOUT_FILENO
%69 = tail call i32 @write(i32 %68, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%70 = icmp eq i32 %69, 17
br i1 %70, label %71, label %91
71: ; preds = %66
%72 = tail call i32 @sleep(i32 60)
%73 = load i32, i32* @STDOUT_FILENO
%74 = tail call i32 @write(i32 %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%75 = icmp eq i32 %74, 17
br i1 %75, label %76, label %91
76: ; preds = %71
%77 = tail call i32 @sleep(i32 60)
%78 = load i32, i32* @STDOUT_FILENO
%79 = tail call i32 @write(i32 %78, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%80 = icmp eq i32 %79, 17
br i1 %80, label %81, label %91
81: ; preds = %76
%82 = tail call i32 @sleep(i32 60)
%83 = load i32, i32* @STDOUT_FILENO
%84 = tail call i32 @write(i32 %83, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%85 = icmp eq i32 %84, 17
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = tail call i32 @sleep(i32 60)
%88 = load i32, i32* @STDOUT_FILENO
%89 = tail call i32 @write(i32 %88, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 17)
%90 = icmp eq i32 %89, 17
br i1 %90, label %93, label %91
91: ; preds = %86, %81, %76, %71, %66, %61, %56, %51, %46, %41
%92 = tail call i32 @exit(i32 0)
unreachable
93: ; preds = %86
%94 = load i32, i32* @STDOUT_FILENO
%95 = tail call i32 @write(i32 %94, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 46)
%96 = tail call i32 @exit(i32 0)
unreachable
}