#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*/ getchar();
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int weather(int diff) {
  srand(time(NULL));
  int whr;
  int whrrand;
  whrrand = (rand() % 100);
  int hot, sunny, cloudy, stormy;
  if (diff == 1) {
    hot = 30;
    sunny = 50;
    cloudy = 10;
    stormy = 10;
  } else if (diff == 2) {
    hot = 20;
    sunny = 50;
    cloudy = 15;
    stormy = 15;
  } else if (diff == 3) {
    hot = 10;
    sunny = 40;
    cloudy = 25;
    stormy = 25;
  }
  if (whrrand > 0 && whrrand <= hot) {
    whr = 1;
  } else if (whrrand > hot && whrrand <= (sunny + hot)) {
    whr = 2;
  } else if (whrrand > (sunny + hot) && whrrand <= (cloudy + sunny + hot)) {
    whr = 3;
  } else if (whrrand > (cloudy + sunny + hot) &&
             whrrand <= (cloudy + sunny + hot + stormy)) {
    whr = 4;
  }
  printf("\n\n\tThe forecast for today is...");
  switch (whr) {
  case 1:
    printf("\n\n\tToday will be such a hot day, your teeth will");
    printf("\n\tprobably melt. You should go get a cold drink!");
    break;
  case 2:
    printf("\n\n\tSeems like the sun is shining today. It is neither");
    printf("\n\ttoo hot nor too cold. Perfect time to play with your kite!");
    break;
  case 3:
    printf("\n\n\tClouds are gathering up high. Maybe it will rain soon?");
    printf("\n\tGo get your yellow umbrella. You know, just in case.");
    break;
  case 4:
    printf("\n\n\tBeware! A storm is coming!");
    printf("\n\tHold your fedora tight!");
    break;
  }
  printf("\n\n\n\tPress Enter to continue... ");
  getchar();
  return whr;
}


x86 assembly (clang, -O0):
<weather>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    11a8 <weather+0x58>
movl   $0x1e,-0x10(%rbp)
movl   $0x32,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
movl   $0xa,-0x1c(%rbp)
jmp    1203 <weather+0xb3>
cmpl   $0x2,-0x4(%rbp)
jne    11d3 <weather+0x83>
movl   $0x14,-0x10(%rbp)
movl   $0x32,-0x14(%rbp)
movl   $0xf,-0x18(%rbp)
movl   $0xf,-0x1c(%rbp)
jmp    11fe <weather+0xae>
cmpl   $0x3,-0x4(%rbp)
jne    11f9 <weather+0xa9>
movl   $0xa,-0x10(%rbp)
movl   $0x28,-0x14(%rbp)
movl   $0x19,-0x18(%rbp)
movl   $0x19,-0x1c(%rbp)
jmp    11fe <weather+0xae>
jmp    1203 <weather+0xb3>
cmpl   $0x0,-0xc(%rbp)
jle    1225 <weather+0xd5>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1225 <weather+0xd5>
movl   $0x1,-0x8(%rbp)
jmp    12c0 <weather+0x170>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    124e <weather+0xfe>
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jg     124e <weather+0xfe>
movl   $0x2,-0x8(%rbp)
jmp    12bb <weather+0x16b>
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jle    127f <weather+0x12f>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jg     127f <weather+0x12f>
movl   $0x3,-0x8(%rbp)
jmp    12b6 <weather+0x166>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jle    12b1 <weather+0x161>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    -0x10(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jg     12b1 <weather+0x161>
movl   $0x4,-0x8(%rbp)
jmp    12b6 <weather+0x166>
jmp    12bb <weather+0x16b>
jmp    12c0 <weather+0x170>
lea    0xd49(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     1364 <weather+0x214>
mov    -0x28(%rbp),%rax
lea    0xd14(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd34(%rip),%rdi
call   1030 <printf@plt>
lea    0xd59(%rip),%rdi
call   1030 <printf@plt>
jmp    1364 <weather+0x214>
lea    0xd79(%rip),%rdi
call   1030 <printf@plt>
lea    0xda3(%rip),%rdi
call   1030 <printf@plt>
jmp    1364 <weather+0x214>
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
jmp    1364 <weather+0x214>
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x8(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weather>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x3,%ebx
je     11a5 <weather+0x55>
mov    $0x32,%ecx
cmp    $0x2,%ebx
jne    11ba <weather+0x6a>
mov    $0xf,%edx
mov    $0x14,%esi
test   %eax,%eax
jg     11c8 <weather+0x78>
jmp    11e2 <weather+0x92>
mov    $0x19,%edx
mov    $0x28,%ecx
mov    $0xa,%esi
test   %eax,%eax
jg     11c8 <weather+0x78>
jmp    11e2 <weather+0x92>
mov    $0xa,%edx
mov    $0x1e,%esi
test   %eax,%eax
jle    11e2 <weather+0x92>
cmp    %esi,%eax
jg     11e2 <weather+0x92>
mov    $0x1,%r14d
lea    0xe78(%rip),%rbx
lea    0xe40(%rip),%rbp
jmp    123c <weather+0xec>
add    %esi,%ecx
cmp    %esi,%eax
jle    1202 <weather+0xb2>
cmp    %ecx,%eax
jg     1202 <weather+0xb2>
mov    $0x2,%r14d
lea    0xebf(%rip),%rbx
lea    0xe82(%rip),%rbp
jmp    123c <weather+0xec>
cmp    %ecx,%eax
setle  %bl
add    %ecx,%edx
cmp    %edx,%eax
setg   %al
or     %bl,%al
lea    0xf4f(%rip),%rcx
lea    0xed7(%rip),%rbp
cmovne %rcx,%rbp
lea    0xf5b(%rip),%rcx
lea    0xeff(%rip),%rbx
cmovne %rcx,%rbx
movzbl %al,%r14d
add    $0x3,%r14d
lea    0xdbd(%rip),%rdi
call   1030 <printf@plt>
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1030 <printf@plt>
lea    0xf3f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0A\0A\09The forecast for today is...\00"
@.str.1 = [49 x i8] c"\0A\0A\09Today will be such a hot day, your teeth will\00"
@.str.2 = [49 x i8] c"\0A\09probably melt. You should go get a cold drink!\00"
@.str.3 = [54 x i8] c"\0A\0A\09Seems like the sun is shining today. It is neither\00"
@.str.4 = [61 x i8] c"\0A\09too hot nor too cold. Perfect time to play with your kite!\00"
@.str.5 = [58 x i8] c"\0A\0A\09Clouds are gathering up high. Maybe it will rain soon?\00"
@.str.6 = [55 x i8] c"\0A\09Go get your yellow umbrella. You know, just in case.\00"
@.str.7 = [30 x i8] c"\0A\0A\09Beware! A storm is coming!\00"
@.str.8 = [26 x i8] c"\0A\09Hold your fedora tight!\00"
@.str.9 = [32 x i8] c"\0A\0A\0A\09Press Enter to continue... \00"
define i32 @weather(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 100
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 30, i32* %5
store i32 50, i32* %6
store i32 10, i32* %7
store i32 10, i32* %8
br label %26
16: ; preds = %1
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 20, i32* %5
store i32 50, i32* %6
store i32 15, i32* %7
store i32 15, i32* %8
br label %25
20: ; preds = %16
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 10, i32* %5
store i32 40, i32* %6
store i32 25, i32* %7
store i32 25, i32* %8
br label %24
24: ; preds = %23, %20
br label %25
25: ; preds = %24, %19
br label %26
26: ; preds = %25, %15
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %3
br label %82
34: ; preds = %29, %26
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = load i32, i32* %5
%42 = add nsw i32 %40, %41
%43 = icmp sle i32 %39, %42
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 2, i32* %3
br label %81
45: ; preds = %38, %34
%46 = load i32, i32* %4
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = add nsw i32 %47, %48
%50 = icmp sgt i32 %46, %49
br i1 %50, label %51, label %60
51: ; preds = %45
%52 = load i32, i32* %4
%53 = load i32, i32* %7
%54 = load i32, i32* %6
%55 = add nsw i32 %53, %54
%56 = load i32, i32* %5
%57 = add nsw i32 %55, %56
%58 = icmp sle i32 %52, %57
br i1 %58, label %59, label %60
59: ; preds = %51
store i32 3, i32* %3
br label %80
60: ; preds = %51, %45
%61 = load i32, i32* %4
%62 = load i32, i32* %7
%63 = load i32, i32* %6
%64 = add nsw i32 %62, %63
%65 = load i32, i32* %5
%66 = add nsw i32 %64, %65
%67 = icmp sgt i32 %61, %66
br i1 %67, label %68, label %79
68: ; preds = %60
%69 = load i32, i32* %4
%70 = load i32, i32* %7
%71 = load i32, i32* %6
%72 = add nsw i32 %70, %71
%73 = load i32, i32* %5
%74 = add nsw i32 %72, %73
%75 = load i32, i32* %8
%76 = add nsw i32 %74, %75
%77 = icmp sle i32 %69, %76
br i1 %77, label %78, label %79
78: ; preds = %68
store i32 4, i32* %3
br label %79
79: ; preds = %78, %68, %60
br label %80
80: ; preds = %79, %59
br label %81
81: ; preds = %80, %44
br label %82
82: ; preds = %81, %33
%83 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%84 = load i32, i32* %3
switch i32 %84, label %97 [
i32 1, label %85
i32 2, label %88
i32 3, label %91
i32 4, label %94
]
85: ; preds = %82
%86 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%87 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %97
88: ; preds = %82
%89 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%90 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
br label %97
91: ; preds = %82
%92 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
%93 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0))
br label %97
94: ; preds = %82
%95 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%96 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %97
97: ; preds = %82, %94, %91, %88, %85
%98 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%99 = call i32 (...) @getchar()
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [32 x i8] c"\0A\0A\09The forecast for today is...\00"
@.str.1 = [49 x i8] c"\0A\0A\09Today will be such a hot day, your teeth will\00"
@.str.2 = [49 x i8] c"\0A\09probably melt. You should go get a cold drink!\00"
@.str.3 = [54 x i8] c"\0A\0A\09Seems like the sun is shining today. It is neither\00"
@.str.4 = [61 x i8] c"\0A\09too hot nor too cold. Perfect time to play with your kite!\00"
@.str.5 = [58 x i8] c"\0A\0A\09Clouds are gathering up high. Maybe it will rain soon?\00"
@.str.6 = [55 x i8] c"\0A\09Go get your yellow umbrella. You know, just in case.\00"
@.str.7 = [30 x i8] c"\0A\0A\09Beware! A storm is coming!\00"
@.str.8 = [26 x i8] c"\0A\09Hold your fedora tight!\00"
@.str.9 = [32 x i8] c"\0A\0A\0A\09Press Enter to continue... \00"
define i32 @weather(i32 %0) {
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 100
switch i32 %0, label %8 [
i32 3, label %7
i32 2, label %6
]
6: ; preds = %1
br label %8
7: ; preds = %1
br label %8
8: ; preds = %1, %6, %7
%9 = phi i32 [ 20, %6 ], [ 10, %7 ], [ 30, %1 ]
%10 = phi i32 [ 50, %6 ], [ 40, %7 ], [ 50, %1 ]
%11 = phi i32 [ 15, %6 ], [ 25, %7 ], [ 10, %1 ]
%12 = icmp slt i32 %5, 1
%13 = icmp sgt i32 %5, %9
%14 = or i1 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %8
%16 = icmp sle i32 %5, %9
%17 = add nuw nsw i32 %10, %9
%18 = icmp sgt i32 %5, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = xor i1 %18, true
%22 = add nuw nsw i32 %17, %11
%23 = icmp sgt i32 %5, %22
%24 = select i1 %21, i1 true, i1 %23
%25 = select i1 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0)
%26 = select i1 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0)
%27 = select i1 %24, i32 4, i32 3
br label %28
28: ; preds = %15, %8, %20
%29 = phi i8* [ %25, %20 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %15 ]
%30 = phi i8* [ %26, %20 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), %15 ]
%31 = phi i32 [ %27, %20 ], [ 1, %8 ], [ 2, %15 ]
%32 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%33 = tail call i32 @printf(i8* dereferenceable(1) %29)
%34 = tail call i32 @printf(i8* dereferenceable(1) %30)
%35 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%36 = tail call i32 (...) @getchar()
ret i32 %31
}