#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 rand();
int /*<<< orphan*/ wait(int);
void generate_weather(int history[][6], int day) {
  int random = (rand() % 6) + 1;
  int *good_weather;
  good_weather = &history[day - 1][6];
  switch (random) {
  case 1:
  case 2:
  case 3:
    *good_weather = 1;
    break;
  case 4:
  case 5:
    *good_weather = 0;
    break;
  case 6:
    if (day == 1) {
      *good_weather = 0;
    } else {
      *good_weather = history[day - 2][6];
    }
    break;
  }
  printf("Weather was ");
  wait(1);
  printf(". ");
  wait(1);
  printf(". ");
  wait(1);
  printf(". ");
  if (*good_weather) {
    printf("\x1B[1;36m"
           "GOOD!");
  } else {
    printf("\x1B[1;31m"
           "BAD!");
  }
  printf("\x1B[0m"
         " (%d)\n",
         random);
}


x86 assembly (clang, -O0):
<generate_weather>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ecx
movslq %ecx,%rax
imul   $0x2aaaaaab,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x20,%rdx
add    %eax,%edx
add    %edx,%edx
mov    %edx,%eax
lea    (%rax,%rax,2),%edx
mov    %ecx,%eax
neg    %edx
mov    %edx,%ecx
lea    0x1(%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
lea    (%rcx,%rcx,2),%rcx
lea    0x18(%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
add    $0xffffffff,%eax
sub    $0x3,%eax
jb     11c9 <generate_weather+0x99>
jmp    11a4 <generate_weather+0x74>
mov    -0x1c(%rbp),%eax
add    $0xfffffffc,%eax
sub    $0x2,%eax
jb     11d8 <generate_weather+0xa8>
jmp    11b8 <generate_weather+0x88>
mov    -0x1c(%rbp),%eax
sub    $0x6,%eax
je     11e7 <generate_weather+0xb7>
jmp    1222 <generate_weather+0xf2>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1222 <generate_weather+0xf2>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    1222 <generate_weather+0xf2>
cmpl   $0x1,-0xc(%rbp)
jne    1200 <generate_weather+0xd0>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    121d <generate_weather+0xed>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x18(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1222 <generate_weather+0xf2>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1298 <generate_weather+0x168>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a6 <generate_weather+0x176>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_weather>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <rand@plt>
movslq %eax,%rbx
imul   $0x2aaaaaab,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
lea    -0x1(%r15),%eax
cltq
lea    (%rax,%rax,2),%rax
lea    (%r14,%rax,8),%r12
add    $0x18,%r12
mov    $0x1,%eax
cmp    $0x3,%ebx
jb     11a8 <generate_weather+0x78>
lea    -0x3(%rbx),%eax
cmp    $0x2,%eax
jae    118b <generate_weather+0x5b>
xor    %eax,%eax
jmp    11a8 <generate_weather+0x78>
cmp    $0x5,%ebx
jne    11ac <generate_weather+0x7c>
xor    %eax,%eax
cmp    $0x1,%r15d
je     11a8 <generate_weather+0x78>
add    $0xfffffffe,%r15d
movslq %r15d,%rax
lea    (%rax,%rax,2),%rax
mov    0x18(%r14,%rax,8),%eax
mov    %eax,(%r12)
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
lea    0xe42(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <wait@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,(%r12)
lea    0xe14(%rip),%rax
lea    0xe00(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
lea    0xe04(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Weather was \00"
@.str.1 = [3 x i8] c". \00"
@.str.2 = [13 x i8] c"\1B[1;36mGOOD!\00"
@.str.3 = [12 x i8] c"\1B[1;31mBAD!\00"
@.str.4 = [11 x i8] c"\1B[0m (%d)\0A\00"
define void @generate_weather([6 x i32]* %0, i32 %1) {
%3 = alloca [6 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store [6 x i32]* %0, [6 x i32]** %3
store i32 %1, i32* %4
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 6
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load [6 x i32]*, [6 x i32]** %3
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %10, i64 %13
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %14, i64 0, i64 6
store i32* %15, i32** %6
%16 = load i32, i32* %5
switch i32 %16, label %36 [
i32 1, label %17
i32 2, label %17
i32 3, label %17
i32 4, label %19
i32 5, label %19
i32 6, label %21
]
17: ; preds = %2, %2, %2
%18 = load i32*, i32** %6
store i32 1, i32* %18
br label %36
19: ; preds = %2, %2
%20 = load i32*, i32** %6
store i32 0, i32* %20
br label %36
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32*, i32** %6
store i32 0, i32* %25
br label %35
26: ; preds = %21
%27 = load [6 x i32]*, [6 x i32]** %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [6 x i32], [6 x i32]* %27, i64 %30
%32 = getelementptr inbounds [6 x i32], [6 x i32]* %31, i64 0, i64 6
%33 = load i32, i32* %32
%34 = load i32*, i32** %6
store i32 %33, i32* %34
br label %35
35: ; preds = %26, %24
br label %36
36: ; preds = %2, %35, %19, %17
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @wait(i32 1)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @wait(i32 1)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @wait(i32 1)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32*, i32** %6
%45 = load i32, i32* %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %36
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %51
49: ; preds = %36
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %52)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Weather was \00"
@.str.1 = [3 x i8] c". \00"
@.str.2 = [13 x i8] c"\1B[1;36mGOOD!\00"
@.str.3 = [12 x i8] c"\1B[1;31mBAD!\00"
@.str.4 = [11 x i8] c"\1B[0m (%d)\0A\00"
define void @generate_weather([6 x i32]* nocapture %0, i32 %1) {
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 6
%5 = add nsw i32 %1, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %6, i64 6
switch i32 %4, label %18 [
i32 0, label %16
i32 1, label %16
i32 2, label %16
i32 3, label %8
i32 4, label %8
i32 5, label %9
]
8: ; preds = %2, %2
br label %16
9: ; preds = %2
%10 = icmp eq i32 %1, 1
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = add nsw i32 %1, -2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %13, i64 6
%15 = load i32, i32* %14
br label %16
16: ; preds = %9, %2, %2, %2, %8, %11
%17 = phi i32 [ %15, %11 ], [ 0, %8 ], [ 1, %2 ], [ 1, %2 ], [ 1, %2 ], [ 0, %9 ]
store i32 %17, i32* %7
br label %18
18: ; preds = %16, %2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @wait(i32 1)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @wait(i32 1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @wait(i32 1)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %28)
%30 = add nsw i32 %4, 1
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %30)
ret void
}