#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*/ free(char *);
unsigned long long get_product(char *);
char *substr(char *, int, int);
unsigned long long largest_product_in_series(char number[],
                                             int product_length) {
  unsigned long long largest = 0;
  for (int i = 0; i < 1000; i += 1) {
    char *buffer = substr(number, i, i + product_length);
    unsigned long long product = get_product(buffer);
    if (product > largest) {
      largest = product;
    }
    free(buffer);
  }
  return largest;
}


x86 assembly (clang, -O0):
<largest_product_in_series>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11ab <largest_product_in_series+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
add    -0xc(%rbp),%edx
call   1040 <substr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <get_product@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1194 <largest_product_in_series+0x64>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <largest_product_in_series+0x1e>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<largest_product_in_series>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r14,%rbx,1),%edx
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <substr@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <get_product@plt>
cmp    %r12,%rax
cmova  %rax,%r12
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
cmp    $0x3e8,%ebx
jne    1150 <largest_product_in_series+0x20>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @largest_product_in_series(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
%18 = call i8* @substr(i8* %13, i32 %14, i32 %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = call i64 @get_product(i8* %19)
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = load i64, i64* %5
%23 = icmp ugt i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = load i64, i64* %8
store i64 %25, i64* %5
br label %26
26: ; preds = %24, %12
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %26
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %9
32: ; preds = %9
%33 = load i64, i64* %5
ret i64 %33
}

LLVM IR (-O2):
define i64 @largest_product_in_series(i8* %0, i32 %1) {
br label %4
3: ; preds = %4
ret i64 %11
4: ; preds = %2, %4
%5 = phi i64 [ 0, %2 ], [ %11, %4 ]
%6 = phi i32 [ 0, %2 ], [ %13, %4 ]
%7 = add nsw i32 %6, %1
%8 = tail call i8* @substr(i8* %0, i32 %6, i32 %7)
%9 = tail call i64 @get_product(i8* %8)
%10 = icmp ugt i64 %9, %5
%11 = select i1 %10, i64 %9, i64 %5
%12 = tail call i32 @free(i8* %8)
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, 1000
br i1 %14, label %3, label %4
}