#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*/ printf(char *);
int scanf(char *, int *, int *, char *);
scalar_t__ strcmp(char *, char *);
char tolower(char);
int main() {
  int hour, minutes;
  char amPm[3];
  printf("Please enter time in format (hh:mm tt): ");
  if (scanf("%d:%d %2s", &hour, &minutes, amPm) != 3) {
    printf("Invalid time format!\n");
    return 1;
  } else if (1 < hour && hour > 12) {
    printf("Hours must be between 1 and 12!\n");
    return 1;
  } else if (0 < minutes && hour > 59) {
    printf("Minutes must be between 0 and 59!\n");
    return 1;
  }
  int i = 0;
  while (amPm[i]) {
    amPm[i] = tolower(amPm[i]);
    i++;
  }
  amPm[2] = '\0';
  char *pm = "pm";
  char *am = "am";
  if ((strcmp(amPm, am) != 0) && (strcmp(amPm, pm) != 0)) {
    printf("tt must be AM or PM!\n");
    return 1;
  }
  int isBeerTime = (hour >= 1 && minutes >= 0 && amPm[0] == 'p') ||
                   (hour < 3 && amPm[0] == 'a');
  if (isBeerTime) {
    printf("beer time\n");
  } else {
    printf("non-beer time\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    -0xf(%rbp),%rcx
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
cmp    $0x3,%eax
je     1194 <main+0x54>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1d8>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    11c4 <main+0x84>
cmpl   $0xc,-0x8(%rbp)
jle    11c4 <main+0x84>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1d8>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jge    11f1 <main+0xb1>
cmpl   $0x3b,-0x8(%rbp)
jle    11f1 <main+0xb1>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1d8>
jmp    11f6 <main+0xb6>
jmp    11fb <main+0xbb>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmpb   $0x0,-0xf(%rbp,%rax,1)
je     1237 <main+0xf7>
movslq -0x14(%rbp),%rax
movsbl -0xf(%rbp,%rax,1),%edi
call   1050 <tolower@plt>
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0xf(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1202 <main+0xc2>
movb   $0x0,-0xd(%rbp)
lea    0xe4b(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0xf(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1297 <main+0x157>
lea    -0xf(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1297 <main+0x157>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1d8>
cmpl   $0x1,-0x8(%rbp)
jl     12bd <main+0x17d>
cmpl   $0x0,-0xc(%rbp)
jl     12bd <main+0x17d>
movsbl -0xf(%rbp),%ecx
mov    $0x1,%al
cmp    $0x70,%ecx
mov    %al,-0x2d(%rbp)
je     12df <main+0x19f>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x2e(%rbp)
jge    12d9 <main+0x199>
movsbl -0xf(%rbp),%eax
cmp    $0x61,%eax
sete   %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1305 <main+0x1c5>
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
jmp    1311 <main+0x1d1>
lea    0xd9d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0xd(%rsp),%rcx
call   1070 <scanf@plt>
mov    $0x1,%ebp
cmp    $0x3,%eax
jne    1197 <main+0x47>
cmpl   $0xc,0x10(%rsp)
jle    11ac <main+0x5c>
lea    0xec7(%rip),%rdi
jmp    119e <main+0x4e>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0xd(%rsp),%al
test   %al,%al
je     11d6 <main+0x86>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11c0 <main+0x70>
movb   $0x0,0xf(%rsp)
lea    0xe54(%rip),%rsi
lea    0xd(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0xc0>
lea    0xe3b(%rip),%rsi
lea    0xd(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0xc0>
lea    0xe39(%rip),%rdi
jmp    119e <main+0x4e>
mov    0x10(%rsp),%eax
xor    %ebp,%ebp
mov    0xd(%rsp),%cl
test   %eax,%eax
jle    1236 <main+0xe6>
cmpl   $0x0,0x14(%rsp)
js     1236 <main+0xe6>
cmp    $0x70,%cl
jne    1236 <main+0xe6>
lea    0xe0c(%rip),%rdi
jmp    119e <main+0x4e>
cmp    $0x61,%cl
lea    0xdfd(%rip),%rdi
lea    0xdf2(%rip),%rcx
cmovne %rcx,%rdi
cmp    $0x3,%eax
cmovge %rcx,%rdi
jmp    119e <main+0x4e>

LLVM IR (-O0):
@.str = [41 x i8] c"Please enter time in format (hh:mm tt): \00"
@.str.1 = [10 x i8] c"%d:%d %2s\00"
@.str.2 = [22 x i8] c"Invalid time format!\0A\00"
@.str.3 = [33 x i8] c"Hours must be between 1 and 12!\0A\00"
@.str.4 = [35 x i8] c"Minutes must be between 0 and 59!\0A\00"
@.str.5 = [3 x i8] c"pm\00"
@.str.6 = [3 x i8] c"am\00"
@.str.7 = [22 x i8] c"tt must be AM or PM!\0A\00"
@.str.8 = [11 x i8] c"beer time\0A\00"
@.str.9 = [15 x i8] c"non-beer time\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i8* %10)
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %95
15: ; preds = %0
%16 = load i32, i32* %2
%17 = icmp slt i32 1, %16
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 12
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %95
23: ; preds = %18, %15
%24 = load i32, i32* %3
%25 = icmp slt i32 0, %24
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, 59
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %95
31: ; preds = %26, %23
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
store i32 0, i32* %5
br label %34
34: ; preds = %40, %33
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = call signext i8 @tolower(i8 signext %44)
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 %47
store i8 %45, i8* %48
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %34
51: ; preds = %34
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %52
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %7
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%54 = load i8*, i8** %7
%55 = call i64 @strcmp(i8* %53, i8* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %51
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%59 = load i8*, i8** %6
%60 = call i64 @strcmp(i8* %58, i8* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %95
64: ; preds = %57, %51
%65 = load i32, i32* %2
%66 = icmp sge i32 %65, 1
br i1 %66, label %67, label %75
67: ; preds = %64
%68 = load i32, i32* %3
%69 = icmp sge i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 112
br i1 %74, label %85, label %75
75: ; preds = %70, %67, %64
%76 = load i32, i32* %2
%77 = icmp slt i32 %76, 3
br i1 %77, label %78, label %83
78: ; preds = %75
%79 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 97
br label %83
83: ; preds = %78, %75
%84 = phi i1 [ false, %75 ], [ %82, %78 ]
br label %85
85: ; preds = %83, %70
%86 = phi i1 [ true, %70 ], [ %84, %83 ]
%87 = zext i1 %86 to i32
store i32 %87, i32* %8
%88 = load i32, i32* %8
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %85
%91 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %94
92: ; preds = %85
%93 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %94
94: ; preds = %92, %90
store i32 0, i32* %1
br label %95
95: ; preds = %94, %62, %29, %21, %13
%96 = load i32, i32* %1
ret i32 %96
}

LLVM IR (-O2):
@.str = [41 x i8] c"Please enter time in format (hh:mm tt): \00"
@.str.1 = [10 x i8] c"%d:%d %2s\00"
@.str.5 = [3 x i8] c"pm\00"
@.str.6 = [3 x i8] c"am\00"
@str = [14 x i8] c"non-beer time\00"
@str.10 = [10 x i8] c"beer time\00"
@str.11 = [21 x i8] c"tt must be AM or PM!\00"
@str.13 = [32 x i8] c"Hours must be between 1 and 12!\00"
@str.14 = [21 x i8] c"Invalid time format!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i8* %6)
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %46
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 12
br i1 %12, label %46, label %13
13: ; preds = %10
%14 = load i8, i8* %6
%15 = icmp eq i8 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13, %16
%17 = phi i64 [ %21, %16 ], [ 0, %13 ]
%18 = phi i8 [ %23, %16 ], [ %14, %13 ]
%19 = phi i8* [ %22, %16 ], [ %6, %13 ]
%20 = call signext i8 @tolower(i8 signext %18)
store i8 %20, i8* %19
%21 = add nuw i64 %17, 1
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %16
25: ; preds = %16, %13
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %26
%27 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %29, %25
%33 = load i32, i32* %1
%34 = icmp sgt i32 %33, 0
%35 = load i32, i32* %2
%36 = icmp sgt i32 %35, -1
%37 = select i1 %34, i1 %36, i1 false
%38 = load i8, i8* %6
%39 = icmp eq i8 %38, 112
%40 = select i1 %37, i1 %39, i1 false
br i1 %40, label %46, label %41
41: ; preds = %32
%42 = icmp slt i32 %33, 3
%43 = icmp eq i8 %38, 97
%44 = select i1 %42, i1 %43, i1 false
%45 = select i1 %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0)
br label %46
46: ; preds = %41, %32, %29, %10, %0
%47 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.14, i64 0, i64 0), %0 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0), %10 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0), %29 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), %32 ], [ %45, %41 ]
%48 = phi i32 [ 1, %0 ], [ 1, %10 ], [ 1, %29 ], [ 0, %32 ], [ 0, %41 ]
%49 = call i32 @puts(i8* dereferenceable(1) %47)
ret i32 %48
}