#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *number_file;
  char *filename;
  char buffer[1000 + 1];
  if (argc > 1) {
    filename = argv[1];
  } else {
    printf("No filename given.\n");
    exit(EXIT_FAILURE);
  }
  number_file = fopen(filename, "r");
  if (NULL == number_file) {
    printf("The file %s does not exist.\n", filename);
    exit(EXIT_FAILURE);
  }
  if (NULL != fgets(buffer, 1000 + 1, number_file)) {
    printf("My buffer is full.\n");
  } else {
    printf("Could not read from the file!\n");
  }
  fclose(number_file);
  int index = 4;
  int d1, d2, d3, d4, d5;
  int currentProduct = 0;
  int maxProduct = 0;
  do {
    d1 = buffer[index - 4] - '0';
    d2 = buffer[index - 3] - '0';
    d3 = buffer[index - 2] - '0';
    d4 = buffer[index - 1] - '0';
    d5 = buffer[index] - '0';
    if (d1 == 0 || d2 == 0 || d3 == 0 || d4 == 0 || d5 == 0) {
      continue;
    }
    currentProduct = d1 * d2 * d3 * d4 * d5;
    if (currentProduct > maxProduct) {
      maxProduct = currentProduct;
    }
  } while (++index < 1000);
  printf("Max product of 5 consecutive digits: %d\n", maxProduct);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1184 <main+0x34>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <main+0x50>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11e0 <main+0x90>
mov    -0x20(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e9,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1216 <main+0xc6>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1224 <main+0xd4>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x414(%rbp)
movl   $0x0,-0x42c(%rbp)
movl   $0x0,-0x430(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x4,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x418(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x3,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x420(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x424(%rbp)
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x418(%rbp)
je     1314 <main+0x1c4>
cmpl   $0x0,-0x41c(%rbp)
je     1314 <main+0x1c4>
cmpl   $0x0,-0x420(%rbp)
je     1314 <main+0x1c4>
cmpl   $0x0,-0x424(%rbp)
je     1314 <main+0x1c4>
cmpl   $0x0,-0x428(%rbp)
jne    1319 <main+0x1c9>
jmp    1364 <main+0x214>
mov    -0x418(%rbp),%eax
imul   -0x41c(%rbp),%eax
imul   -0x420(%rbp),%eax
imul   -0x424(%rbp),%eax
imul   -0x428(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x430(%rbp),%eax
jle    135f <main+0x20f>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x430(%rbp)
jmp    1364 <main+0x214>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
cmp    $0x3e8,%eax
jl     124b <main+0xfb>
mov    -0x430(%rbp),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
cmp    $0x2,%edi
jl     119b <main+0x3b>
mov    0x8(%rsi),%r14
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11b5 <main+0x55>
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a7 <main+0x47>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x3e9,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
lea    0xe89(%rip),%rax
lea    0xea0(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%r11b
mov    0x1(%rsp),%r10b
mov    0x2(%rsp),%r9b
xor    %esi,%esi
mov    $0x4,%edx
mov    0x3(%rsp),%r8b
jmp    121d <main+0xbd>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    $0x3e8,%rdx
je     126a <main+0x10a>
movsbl %r11b,%ebx
mov    %r10d,%r11d
mov    %r9d,%r10d
mov    %r8d,%r9d
movsbl (%rsp,%rdx,1),%r8d
add    $0xffffffd0,%ebx
je     1210 <main+0xb0>
movsbl %r11b,%edi
add    $0xffffffd0,%edi
je     1210 <main+0xb0>
movsbl %r10b,%ecx
add    $0xffffffd0,%ecx
je     1210 <main+0xb0>
movsbl %r9b,%eax
add    $0xffffffd0,%eax
je     1210 <main+0xb0>
mov    %r8d,%ebp
add    $0xffffffd0,%ebp
je     1210 <main+0xb0>
imul   %ebx,%edi
imul   %ecx,%edi
imul   %eax,%edi
imul   %ebp,%edi
cmp    %esi,%edi
cmovg  %edi,%esi
jmp    1210 <main+0xb0>
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"No filename given.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"The file %s does not exist.\0A\00"
@.str.3 = [20 x i8] c"My buffer is full.\0A\00"
@.str.4 = [31 x i8] c"Could not read from the file!\0A\00"
@.str.5 = [41 x i8] c"Max product of 5 consecutive digits: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [1001 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %7
br label %27
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i8*, i8** %7
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp eq i32* null, %30
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%38 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32* @fgets(i8* %38, i32 1001, i32* %39)
%41 = icmp ne i32* null, %40
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %46
44: ; preds = %37
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
store i32 4, i32* %9
store i32 0, i32* %15
store i32 0, i32* %16
br label %49
49: ; preds = %115, %46
%50 = load i32, i32* %9
%51 = sub nsw i32 %50, 4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = sub nsw i32 %55, 48
store i32 %56, i32* %10
%57 = load i32, i32* %9
%58 = sub nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = sub nsw i32 %62, 48
store i32 %63, i32* %11
%64 = load i32, i32* %9
%65 = sub nsw i32 %64, 2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = sub nsw i32 %69, 48
store i32 %70, i32* %12
%71 = load i32, i32* %9
%72 = sub nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = sub nsw i32 %76, 48
store i32 %77, i32* %13
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [1001 x i8], [1001 x i8]* %8, i64 0, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = sub nsw i32 %82, 48
store i32 %83, i32* %14
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 0
br i1 %85, label %98, label %86
86: ; preds = %49
%87 = load i32, i32* %11
%88 = icmp eq i32 %87, 0
br i1 %88, label %98, label %89
89: ; preds = %86
%90 = load i32, i32* %12
%91 = icmp eq i32 %90, 0
br i1 %91, label %98, label %92
92: ; preds = %89
%93 = load i32, i32* %13
%94 = icmp eq i32 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %92
%96 = load i32, i32* %14
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %95, %92, %89, %86, %49
br label %115
99: ; preds = %95
%100 = load i32, i32* %10
%101 = load i32, i32* %11
%102 = mul nsw i32 %100, %101
%103 = load i32, i32* %12
%104 = mul nsw i32 %102, %103
%105 = load i32, i32* %13
%106 = mul nsw i32 %104, %105
%107 = load i32, i32* %14
%108 = mul nsw i32 %106, %107
store i32 %108, i32* %15
%109 = load i32, i32* %15
%110 = load i32, i32* %16
%111 = icmp sgt i32 %109, %110
br i1 %111, label %112, label %114
112: ; preds = %99
%113 = load i32, i32* %15
store i32 %113, i32* %16
br label %114
114: ; preds = %112, %99
br label %115
115: ; preds = %114, %98
%116 = load i32, i32* %9
%117 = add nsw i32 %116, 1
store i32 %117, i32* %9
%118 = icmp slt i32 %117, 1000
br i1 %118, label %49, label %119
119: ; preds = %115
%120 = load i32, i32* %16
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %120)
%122 = load i32, i32* @EXIT_SUCCESS
%123 = call i32 @exit(i32 %122)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"The file %s does not exist.\0A\00"
@.str.5 = [41 x i8] c"Max product of 5 consecutive digits: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"No filename given.\00"
@str.6 = [30 x i8] c"Could not read from the file!\00"
@str.7 = [19 x i8] c"My buffer is full.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1001 x i8]
%4 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %19
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %6
%20 = call i32* @fgets(i8* %4, i32 1001, i32* %9)
%21 = icmp eq i32* %20, null
%22 = select i1 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0)
%23 = call i32 @puts(i8* dereferenceable(1) %22)
%24 = call i32 @fclose(i32* %9)
%25 = load i8, i8* %4
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 1
%27 = load i8, i8* %26
%28 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 2
%29 = load i8, i8* %28
%30 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 3
%31 = load i8, i8* %30
br label %32
32: ; preds = %67, %19
%33 = phi i8 [ %48, %67 ], [ %31, %19 ]
%34 = phi i8 [ %33, %67 ], [ %29, %19 ]
%35 = phi i8 [ %34, %67 ], [ %27, %19 ]
%36 = phi i8 [ %35, %67 ], [ %25, %19 ]
%37 = phi i64 [ %69, %67 ], [ 4, %19 ]
%38 = phi i32 [ %68, %67 ], [ 0, %19 ]
%39 = sext i8 %36 to i32
%40 = add nsw i32 %39, -48
%41 = sext i8 %35 to i32
%42 = add nsw i32 %41, -48
%43 = sext i8 %34 to i32
%44 = add nsw i32 %43, -48
%45 = sext i8 %33 to i32
%46 = add nsw i32 %45, -48
%47 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 %37
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = add nsw i32 %49, -48
%51 = icmp eq i32 %40, 0
%52 = icmp eq i32 %42, 0
%53 = select i1 %51, i1 true, i1 %52
%54 = icmp eq i32 %44, 0
%55 = select i1 %53, i1 true, i1 %54
%56 = icmp eq i32 %46, 0
%57 = select i1 %55, i1 true, i1 %56
%58 = icmp eq i32 %50, 0
%59 = select i1 %57, i1 true, i1 %58
br i1 %59, label %67, label %60
60: ; preds = %32
%61 = mul nsw i32 %42, %40
%62 = mul nsw i32 %61, %44
%63 = mul nsw i32 %62, %46
%64 = mul nsw i32 %63, %50
%65 = icmp sgt i32 %64, %38
%66 = select i1 %65, i32 %64, i32 %38
br label %67
67: ; preds = %60, %32
%68 = phi i32 [ %38, %32 ], [ %66, %60 ]
%69 = add nuw nsw i64 %37, 1
%70 = icmp eq i64 %69, 1000
br i1 %70, label %71, label %32
71: ; preds = %67
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %68)
%73 = load i32, i32* @EXIT_SUCCESS
%74 = call i32 @exit(i32 %73)
unreachable
}