#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 *, ...);
void post_weather_update(int history[][6], int day) {
  int pots_in = history[day - 1][4];
  int pots_out = history[day - 1][2] - pots_in;
  int good_weather = history[day - 1][6];
  int money_earned;
  if (good_weather) {
    money_earned = pots_in * 2 + pots_out * 6;
    printf("\x1B[0m"
           "You earned $");
    printf("\x1B[1;32m"
           "%d\n",
           money_earned);
  } else {
    money_earned = pots_in * 4;
    history[day][2] -= pots_out;
    printf("\x1B[0m"
           "You earned $");
    printf("\x1B[1;32m"
           "%d",
           money_earned);
    printf("\x1B[0m"
           ", however you lost ");
    printf("\x1B[1;31m"
           "%d",
           pots_out);
    printf("\x1B[0m"
           " pots.\n");
  }
  history[day - 1][5] = money_earned;
  history[day][1] += money_earned;
}


x86 assembly (clang, -O0):
<post_weather_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x18(%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ad <post_weather_update+0x9d>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
imul   $0x6,-0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <post_weather_update+0x10c>
mov    -0x10(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
sub    %edx,%ecx
mov    %ecx,0x8(%rax)
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x14(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rdx
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
add    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<post_weather_update>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
lea    -0x1(%r12),%eax
cltq
lea    (%rax,%rax,2),%r13
mov    0x8(%rdi,%r13,8),%r15d
mov    0x10(%rdi,%r13,8),%ebx
sub    %ebx,%r15d
cmpl   $0x0,0x18(%rdi,%r13,8)
je     117b <post_weather_update+0x5b>
add    %ebx,%ebx
lea    (%r15,%r15,2),%eax
lea    (%rbx,%rax,2),%ebx
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %r12d,%r12
jmp    11d3 <post_weather_update+0xb3>
shl    $0x2,%ebx
movslq %r12d,%r12
lea    (%r12,%r12,2),%rax
sub    %r15d,0x8(%r14,%rax,8)
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe81(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,0x14(%r14,%r13,8)
lea    (%r12,%r12,2),%rax
add    %ebx,0x4(%r14,%rax,8)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\1B[0mYou earned $\00"
@.str.1 = [11 x i8] c"\1B[1;32m%d\0A\00"
@.str.2 = [10 x i8] c"\1B[1;32m%d\00"
@.str.3 = [24 x i8] c"\1B[0m, however you lost \00"
@.str.4 = [10 x i8] c"\1B[1;31m%d\00"
@.str.5 = [12 x i8] c"\1B[0m pots.\0A\00"
define void @post_weather_update([6 x i32]* %0, i32 %1) {
%3 = alloca [6 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store [6 x i32]* %0, [6 x i32]** %3
store i32 %1, i32* %4
%9 = load [6 x i32]*, [6 x i32]** %3
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %9, i64 %12
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 4
%15 = load i32, i32* %14
store i32 %15, i32* %5
%16 = load [6 x i32]*, [6 x i32]** %3
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %16, i64 %19
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %20, i64 0, i64 2
%22 = load i32, i32* %21
%23 = load i32, i32* %5
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %6
%25 = load [6 x i32]*, [6 x i32]** %3
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [6 x i32], [6 x i32]* %25, i64 %28
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %29, i64 0, i64 6
%31 = load i32, i32* %30
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %2
%35 = load i32, i32* %5
%36 = mul nsw i32 %35, 2
%37 = load i32, i32* %6
%38 = mul nsw i32 %37, 6
%39 = add nsw i32 %36, %38
store i32 %39, i32* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %61
43: ; preds = %2
%44 = load i32, i32* %5
%45 = mul nsw i32 %44, 4
store i32 %45, i32* %8
%46 = load i32, i32* %6
%47 = load [6 x i32]*, [6 x i32]** %3
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [6 x i32], [6 x i32]* %47, i64 %49
%51 = getelementptr inbounds [6 x i32], [6 x i32]* %50, i64 0, i64 2
%52 = load i32, i32* %51
%53 = sub nsw i32 %52, %46
store i32 %53, i32* %51
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%55 = load i32, i32* %8
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %43, %34
%62 = load i32, i32* %8
%63 = load [6 x i32]*, [6 x i32]** %3
%64 = load i32, i32* %4
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [6 x i32], [6 x i32]* %63, i64 %66
%68 = getelementptr inbounds [6 x i32], [6 x i32]* %67, i64 0, i64 5
store i32 %62, i32* %68
%69 = load i32, i32* %8
%70 = load [6 x i32]*, [6 x i32]** %3
%71 = load i32, i32* %4
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [6 x i32], [6 x i32]* %70, i64 %72
%74 = getelementptr inbounds [6 x i32], [6 x i32]* %73, i64 0, i64 1
%75 = load i32, i32* %74
%76 = add nsw i32 %75, %69
store i32 %76, i32* %74
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"\1B[0mYou earned $\00"
@.str.1 = [11 x i8] c"\1B[1;32m%d\0A\00"
@.str.2 = [10 x i8] c"\1B[1;32m%d\00"
@.str.3 = [24 x i8] c"\1B[0m, however you lost \00"
@.str.4 = [10 x i8] c"\1B[1;31m%d\00"
@str = [11 x i8] c"\1B[0m pots.\00"
define void @post_weather_update([6 x i32]* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 4
%6 = load i32, i32* %5
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 2
%8 = load i32, i32* %7
%9 = sub nsw i32 %8, %6
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 6
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = shl nsw i32 %6, 1
%15 = mul nsw i32 %9, 6
%16 = add nsw i32 %15, %14
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%19 = sext i32 %1 to i64
br label %31
20: ; preds = %2
%21 = shl nsw i32 %6, 2
%22 = sext i32 %1 to i64
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %22, i64 2
%24 = load i32, i32* %23
%25 = sub nsw i32 %24, %9
store i32 %25, i32* %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %20, %13
%32 = phi i64 [ %22, %20 ], [ %19, %13 ]
%33 = phi i32 [ %21, %20 ], [ %16, %13 ]
%34 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %4, i64 5
store i32 %33, i32* %34
%35 = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 %32, i64 1
%36 = load i32, i32* %35
%37 = add nsw i32 %36, %33
store i32 %37, i32* %35
ret void
}