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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strtok(char *, char *);
long strtol(char *, char **, int);
long solve(const char *filename) {
  FILE *fp;
  char *line = NULL;
  ssize_t read;
  size_t len = 0;
  char *token = NULL;
  char *str_end;
  long sides[3];
  long max = 0;
  int i = 0;
  long packing_paper = 0;
  fp = fopen(filename, "r");
  while ((read = getline(&line, &len, fp)) != -1) {
    token = strtok(line, "x");
    for (i = 0; i < 3; i++, token = strtok(NULL, "x")) {
      sides[i] = strtol(token, &str_end, 10);
    }
    for (i = 0; i < 3; i++) {
      packing_paper += 2 * sides[i] * sides[(i + 1) % 3];
    }
    for (i = 1, max = 0; i < 3; i++) {
      if (sides[max] < sides[i]) {
        max = i;
      }
    }
    packing_paper += sides[(max + 1) % 3] * sides[(max + 2) % 3];
  }
  fclose(fp);
  if (line) {
    free(line);
  }
  return packing_paper;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1317 <solve+0x1b7>
mov    -0x18(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    1234 <solve+0xd4>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
movslq -0x5c(%rbp),%rax
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xddc(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11ea <solve+0x8a>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    1287 <solve+0x127>
movslq -0x5c(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rax
shl    $0x1,%rax
mov    %rax,-0x70(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x70(%rbp),%rax
movslq %edx,%rcx
imul   -0x50(%rbp,%rcx,8),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    123b <solve+0xdb>
movl   $0x1,-0x5c(%rbp)
movq   $0x0,-0x58(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    12d3 <solve+0x173>
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rax
movslq -0x5c(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,8),%rax
jge    12c0 <solve+0x160>
movslq -0x5c(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    12c5 <solve+0x165>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1296 <solve+0x136>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    -0x50(%rbp,%rdx,8),%rax
mov    %rax,-0x78(%rbp)
mov    -0x58(%rbp),%rax
add    $0x2,%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    -0x78(%rbp),%rax
imul   -0x50(%rbp,%rdx,8),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    11b2 <solve+0x52>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     1334 <solve+0x1d4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rax,0x10(%rsp)
mov    %rax,%rdx
call   1080 <getline@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     12d6 <solve+0x176>
lea    0xe4d(%rip),%rbx
lea    0x40(%rsp),%r15
jmp    122e <solve+0xce>
nopl   0x0(%rax)
lea    0x0(,%rax,2),%rax
add    %rbp,%rax
lea    (%rax,%rdx,2),%rax
lea    (%rax,%rsi,2),%rax
lea    0x1(%rcx),%edx
movzbl %dl,%edx
imul   $0xab,%edx,%esi
shr    $0x9,%esi
lea    (%rsi,%rsi,2),%esi
sub    %sil,%dl
movzbl %dl,%edx
add    $0x2,%cl
movzbl %cl,%ecx
imul   $0xab,%ecx,%esi
shr    $0x9,%esi
lea    (%rsi,%rsi,2),%esi
sub    %sil,%cl
movzbl %cl,%ecx
mov    0x20(%rsp,%rcx,8),%rbp
imul   0x20(%rsp,%rdx,8),%rbp
add    %rax,%rbp
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     12d6 <solve+0x176>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r12
mov    %rax,0x20(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r13
mov    %rax,0x28(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
mov    %rax,0x30(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %r12,%rax
imul   %r13,%rax
mov    %r13,%rdx
imul   %r14,%rdx
mov    %r14,%rsi
imul   %r12,%rsi
xor    %edi,%edi
cmp    %r13,%r12
setl   %dil
mov    $0x2,%ecx
cmp    %r14,0x20(%rsp,%rdi,8)
jl     11c0 <solve+0x60>
mov    %edi,%ecx
jmp    11c0 <solve+0x60>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12ef <solve+0x18f>
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"x\00"
define i64 @solve(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i64]
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
store i64 0, i64* %6
store i8* null, i8** %7
store i64 0, i64* %10
store i32 0, i32* %11
store i64 0, i64* %12
%13 = load i8*, i8** %2
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %3
br label %15
15: ; preds = %77, %1
%16 = load i32*, i32** %3
%17 = call i32 @getline(i8** %4, i64* %6, i32* %16)
store i32 %17, i32* %5
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %91
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %7
store i32 0, i32* %11
br label %22
22: ; preds = %31, %19
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i64 @strtol(i8* %26, i8** %8, i32 10)
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %29
store i64 %27, i64* %30
br label %31
31: ; preds = %25
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %34, i8** %7
br label %22
35: ; preds = %22
store i32 0, i32* %11
br label %36
36: ; preds = %54, %35
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 3
br i1 %38, label %39, label %57
39: ; preds = %36
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %41
%43 = load i64, i64* %42
%44 = mul nsw i64 2, %43
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
%47 = srem i32 %46, 3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %48
%50 = load i64, i64* %49
%51 = mul nsw i64 %44, %50
%52 = load i64, i64* %12
%53 = add nsw i64 %52, %51
store i64 %53, i64* %12
br label %54
54: ; preds = %39
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %36
57: ; preds = %36
store i32 1, i32* %11
store i64 0, i64* %10
br label %58
58: ; preds = %74, %57
%59 = load i32, i32* %11
%60 = icmp slt i32 %59, 3
br i1 %60, label %61, label %77
61: ; preds = %58
%62 = load i64, i64* %10
%63 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %62
%64 = load i64, i64* %63
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %66
%68 = load i64, i64* %67
%69 = icmp slt i64 %64, %68
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
store i64 %72, i64* %10
br label %73
73: ; preds = %70, %61
br label %74
74: ; preds = %73
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %58
77: ; preds = %58
%78 = load i64, i64* %10
%79 = add nsw i64 %78, 1
%80 = srem i64 %79, 3
%81 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %80
%82 = load i64, i64* %81
%83 = load i64, i64* %10
%84 = add nsw i64 %83, 2
%85 = srem i64 %84, 3
%86 = getelementptr inbounds [3 x i64], [3 x i64]* %9, i64 0, i64 %85
%87 = load i64, i64* %86
%88 = mul nsw i64 %82, %87
%89 = load i64, i64* %12
%90 = add nsw i64 %89, %88
store i64 %90, i64* %12
br label %15
91: ; preds = %15
%92 = load i32*, i32** %3
%93 = call i32 @fclose(i32* %92)
%94 = load i8*, i8** %4
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i8*, i8** %4
%98 = call i32 @free(i8* %97)
br label %99
99: ; preds = %96, %91
%100 = load i64, i64* %12
ret i64 %100
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"x\00"
define i64 @solve(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [3 x i64]
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%8 = bitcast i8** %4 to i8*
%9 = bitcast [3 x i64]* %5 to i8*
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @getline(i8** %2, i64* %3, i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %58, label %13
13: ; preds = %1
%14 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 0
%15 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 1
%16 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 2
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ %55, %17 ], [ 0, %13 ]
%19 = load i8*, i8** %2
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i64 @strtol(i8* %20, i8** %4, i32 10)
store i64 %21, i64* %14
%22 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = call i64 @strtol(i8* %22, i8** %4, i32 10)
store i64 %23, i64* %15
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = call i64 @strtol(i8* %24, i8** %4, i32 10)
store i64 %25, i64* %16
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = shl nsw i64 %21, 1
%28 = mul nsw i64 %27, %23
%29 = shl nsw i64 %23, 1
%30 = mul nsw i64 %29, %25
%31 = shl nsw i64 %25, 1
%32 = mul nsw i64 %31, %21
%33 = icmp slt i64 %21, %23
%34 = zext i1 %33 to i64
%35 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 %34
%36 = load i64, i64* %35
%37 = icmp slt i64 %36, %25
%38 = select i1 %37, i64 2, i64 %34
%39 = add nsw i64 %28, %18
%40 = add nsw i64 %30, %39
%41 = add nsw i64 %32, %40
%42 = trunc i64 %38 to i8
%43 = add nuw nsw i8 %42, 1
%44 = urem i8 %43, 3
%45 = zext i8 %44 to i64
%46 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 %45
%47 = load i64, i64* %46
%48 = trunc i64 %38 to i8
%49 = add nuw nsw i8 %48, 2
%50 = urem i8 %49, 3
%51 = zext i8 %50 to i64
%52 = getelementptr inbounds [3 x i64], [3 x i64]* %5, i64 0, i64 %51
%53 = load i64, i64* %52
%54 = mul nsw i64 %53, %47
%55 = add nsw i64 %54, %41
%56 = call i32 @getline(i8** %2, i64* %3, i32* %10)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %17
58: ; preds = %17, %1
%59 = phi i64 [ 0, %1 ], [ %55, %17 ]
%60 = call i32 @fclose(i32* %10)
%61 = load i8*, i8** %2
%62 = icmp eq i8* %61, null
br i1 %62, label %65, label %63
63: ; preds = %58
%64 = call i32 @free(i8* %61)
br label %65
65: ; preds = %63, %58
ret i64 %59
}