#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 max_profit_multiple_transactions(int *, int);
int max_profit_one_transaction(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int stock_a[6] = {7, 1, 5, 3, 6, 4};
  int stock_b[5] = {7, 6, 4, 3, 1};
  int stock_c[7] = {1, 3, 4, 6, 7, 9};
  printf("Max profit of the following stock day prices windows:\n[");
  for (int i = 0; i < 6; i++)
    printf("%d, ", stock_a[i]);
  printf("]\n   one transaction %d\n", max_profit_one_transaction(stock_a, 6));
  printf("   multiple transactions %d\n[",
         max_profit_multiple_transactions(stock_a, 6));
  for (int i = 0; i < 5; i++)
    printf("%d, ", stock_b[i]);
  printf("]\n   one transaction %d\n", max_profit_one_transaction(stock_b, 5));
  printf("   multiple transactions %d\n[",
         max_profit_multiple_transactions(stock_b, 6));
  for (int i = 0; i < 6; i++)
    printf("%d, ", stock_c[i]);
  printf("]\n   one transaction %d\n", max_profit_one_transaction(stock_c, 7));
  printf("   multiple transactions %d\n",
         max_profit_multiple_transactions(stock_c, 6));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb4(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xeb2(%rip),%eax
mov    %eax,-0x48(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x6,-0x64(%rbp)
jge    11ec <main+0xbc>
movslq -0x64(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11be <main+0x8e>
lea    -0x20(%rbp),%rdi
mov    $0x6,%esi
call   1030 <max_profit_one_transaction@plt>
mov    %eax,%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x68(%rbp)
cmpl   $0x5,-0x68(%rbp)
jge    125d <main+0x12d>
movslq -0x68(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    122f <main+0xff>
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
call   1030 <max_profit_one_transaction@plt>
mov    %eax,%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
mov    %eax,%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x6,-0x6c(%rbp)
jge    12ce <main+0x19e>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12a0 <main+0x170>
lea    -0x60(%rbp),%rdi
mov    $0x7,%esi
call   1030 <max_profit_one_transaction@plt>
mov    %eax,%esi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
mov    %eax,%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0xece(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xed7(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xedd(%rip),%xmm0
movups %xmm0,0x4c(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeff(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x6,%esi
call   1030 <max_profit_one_transaction@plt>
lea    0xe91(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
lea    0xe8a(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x5,%esi
call   1030 <max_profit_one_transaction@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <max_profit_one_transaction@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1050 <max_profit_multiple_transactions@plt>
lea    0xd90(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.stock_a = [6 x i32] [i32 7, i32 1, i32 5, i32 3, i32 6, i32 4]
@__const.main.stock_b = [5 x i32] [i32 7, i32 6, i32 4, i32 3, i32 1]
@__const.main.stock_c = [7 x i32] [i32 1, i32 3, i32 4, i32 6, i32 7, i32 9, i32 0]
@.str = [56 x i8] c"Max profit of the following stock day prices windows:\0A[\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [25 x i8] c"]\0A one transaction %d\0A\00"
@.str.3 = [30 x i8] c" multiple transactions %d\0A[\00"
@.str.4 = [29 x i8] c" multiple transactions %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i32]
%3 = alloca [5 x i32]
%4 = alloca [7 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [6 x i32]* %2 to i8*
%9 = bitcast [5 x i32]* %3 to i8*
%10 = bitcast [7 x i32]* %4 to i8*
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 6
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%26 = call i32 @max_profit_one_transaction(i32* %25, i32 6)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%29 = call i32 @max_profit_multiple_transactions(i32* %28, i32 6)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %29)
store i32 0, i32* %6
br label %31
31: ; preds = %40, %24
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 5
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %31
43: ; preds = %31
%44 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%45 = call i32 @max_profit_one_transaction(i32* %44, i32 5)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%48 = call i32 @max_profit_multiple_transactions(i32* %47, i32 6)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %48)
store i32 0, i32* %7
br label %50
50: ; preds = %59, %43
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 6
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %53
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %50
62: ; preds = %50
%63 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 0
%64 = call i32 @max_profit_one_transaction(i32* %63, i32 7)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 0
%67 = call i32 @max_profit_multiple_transactions(i32* %66, i32 6)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %67)
ret i32 0
}

LLVM IR (-O2):
@__const.main.stock_a = [6 x i32] [i32 7, i32 1, i32 5, i32 3, i32 6, i32 4]
@__const.main.stock_b = [5 x i32] [i32 7, i32 6, i32 4, i32 3, i32 1]
@__const.main.stock_c = [7 x i32] [i32 1, i32 3, i32 4, i32 6, i32 7, i32 9, i32 0]
@.str = [56 x i8] c"Max profit of the following stock day prices windows:\0A[\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [25 x i8] c"]\0A one transaction %d\0A\00"
@.str.3 = [30 x i8] c" multiple transactions %d\0A[\00"
@.str.4 = [29 x i8] c" multiple transactions %d\0A\00"
define i32 @main() {
%1 = alloca [6 x i32]
%2 = alloca [5 x i32]
%3 = alloca [7 x i32]
%4 = bitcast [6 x i32]* %1 to i8*
%5 = bitcast [5 x i32]* %2 to i8*
%6 = bitcast [7 x i32]* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 7)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = call i32 @max_profit_one_transaction(i32* %8, i32 6)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @max_profit_multiple_transactions(i32* %8, i32 6)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 7)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1)
%25 = call i32 @max_profit_one_transaction(i32* %19, i32 5)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 @max_profit_multiple_transactions(i32* %19, i32 6)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 7)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 9)
%36 = call i32 @max_profit_one_transaction(i32* %29, i32 7)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = call i32 @max_profit_multiple_transactions(i32* %29, i32 6)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %38)
ret i32 0
}