#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
scalar_t__ min(int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *file;
  int x, y, z;
  int s1, s2, s3;
  int total, total_ribbon;
  if (argc < 2) {
    fprintf(stdout, "Usage: %s <file>\n", argv[0]);
    return 0;
  }
  file = fopen(argv[1], "r");
  if (!file) {
    fprintf(stderr, "Error: Opening File: %s\n", argv[1]);
    return 1;
  }
  total = 0;
  total_ribbon = 0;
  while (fscanf(file, "%dx%dx%d\n", &x, &y, &z) != EOF) {
    s1 = x * y;
    s2 = y * z;
    s3 = z * x;
    total += (2 * s1);
    total += (2 * s2);
    total += (2 * s3);
    total += min(s1, s2, s3);
    s1 = 2 * (x + y);
    s2 = 2 * (y + z);
    s3 = 2 * (z + x);
    total_ribbon += min(s1, s2, s3);
    total_ribbon += x * y * z;
  }
  fprintf(stdout, "They should order %d square feet of paper\n", total);
  fprintf(stdout, "They should order %d feet of ribbon\n", total_ribbon);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1318 <main+0x1c8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e8 <main+0x98>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1c8>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1050 <fscanf@plt>
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <main+0x184>
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1040 <min@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1040 <min@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11f6 <main+0xa6>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     1188 <main+0x38>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe86(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12d3 <main+0x183>
mov    0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12b3 <main+0x163>
mov    %rax,%r12
lea    0xe82(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e1f(%rip),%r15
mov    $0x0,%ebx
mov    $0x0,%ebp
cmp    (%r15),%rax
je     127a <main+0x12a>
xor    %ebp,%ebp
xor    %ebx,%ebx
mov    %ebx,0x14(%rsp)
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%r13d
mov    0x8(%rsp),%r14d
mov    %r12,%rbx
mov    %r14d,%r12d
imul   %r13d,%r12d
imul   %eax,%r13d
imul   %eax,%r14d
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r14d,%edx
call   1040 <min@plt>
add    %r12d,%r13d
mov    %rbx,%r12
add    %r14d,%r13d
add    0x14(%rsp),%eax
lea    (%rax,%r13,2),%ebx
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%esi
lea    (%rsi,%rax,1),%edi
add    %edi,%edi
mov    0x8(%rsp),%edx
add    %edx,%esi
add    %esi,%esi
add    %eax,%edx
add    %edx,%edx
call   1040 <min@plt>
add    %ebp,%eax
mov    0xc(%rsp),%ebp
imul   0x10(%rsp),%ebp
imul   0x8(%rsp),%ebp
add    %eax,%ebp
mov    %r12,%rdi
lea    0xdd0(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1050 <fscanf@plt>
cmp    (%r15),%rax
jne    11e0 <main+0x90>
mov    0x2d4f(%rip),%r14
mov    (%r14),%edi
lea    0xdac(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xdc4(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
jmp    12d3 <main+0x183>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xd4d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Error: Opening File: %s\0A\00"
@.str.3 = [10 x i8] c"%dx%dx%d\0A\00"
@EOF = global i64 0
@.str.4 = [43 x i8] c"They should order %d square feet of paper\0A\00"
@.str.5 = [37 x i8] c"They should order %d feet of ribbon\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stdout
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %108
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %36, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %108
36: ; preds = %23
store i32 0, i32* %13
store i32 0, i32* %14
br label %37
37: ; preds = %42, %36
%38 = load i32*, i32** %6
%39 = call i64 @fscanf(i32* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%40 = load i64, i64* @EOF
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %99
42: ; preds = %37
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = mul nsw i32 %43, %44
store i32 %45, i32* %10
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = mul nsw i32 %46, %47
store i32 %48, i32* %11
%49 = load i32, i32* %9
%50 = load i32, i32* %7
%51 = mul nsw i32 %49, %50
store i32 %51, i32* %12
%52 = load i32, i32* %10
%53 = mul nsw i32 2, %52
%54 = load i32, i32* %13
%55 = add nsw i32 %54, %53
store i32 %55, i32* %13
%56 = load i32, i32* %11
%57 = mul nsw i32 2, %56
%58 = load i32, i32* %13
%59 = add nsw i32 %58, %57
store i32 %59, i32* %13
%60 = load i32, i32* %12
%61 = mul nsw i32 2, %60
%62 = load i32, i32* %13
%63 = add nsw i32 %62, %61
store i32 %63, i32* %13
%64 = load i32, i32* %10
%65 = load i32, i32* %11
%66 = load i32, i32* %12
%67 = call i64 @min(i32 %64, i32 %65, i32 %66)
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = add nsw i64 %69, %67
%71 = trunc i64 %70 to i32
store i32 %71, i32* %13
%72 = load i32, i32* %7
%73 = load i32, i32* %8
%74 = add nsw i32 %72, %73
%75 = mul nsw i32 2, %74
store i32 %75, i32* %10
%76 = load i32, i32* %8
%77 = load i32, i32* %9
%78 = add nsw i32 %76, %77
%79 = mul nsw i32 2, %78
store i32 %79, i32* %11
%80 = load i32, i32* %9
%81 = load i32, i32* %7
%82 = add nsw i32 %80, %81
%83 = mul nsw i32 2, %82
store i32 %83, i32* %12
%84 = load i32, i32* %10
%85 = load i32, i32* %11
%86 = load i32, i32* %12
%87 = call i64 @min(i32 %84, i32 %85, i32 %86)
%88 = load i32, i32* %14
%89 = sext i32 %88 to i64
%90 = add nsw i64 %89, %87
%91 = trunc i64 %90 to i32
store i32 %91, i32* %14
%92 = load i32, i32* %7
%93 = load i32, i32* %8
%94 = mul nsw i32 %92, %93
%95 = load i32, i32* %9
%96 = mul nsw i32 %94, %95
%97 = load i32, i32* %14
%98 = add nsw i32 %97, %96
store i32 %98, i32* %14
br label %37
99: ; preds = %37
%100 = load i32, i32* @stdout
%101 = load i32, i32* %13
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %101)
%103 = load i32, i32* @stdout
%104 = load i32, i32* %14
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %104)
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
store i32 0, i32* %3
br label %108
108: ; preds = %99, %30, %17
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Error: Opening File: %s\0A\00"
@.str.3 = [10 x i8] c"%dx%dx%d\0A\00"
@EOF = global i64 0
@.str.4 = [43 x i8] c"They should order %d square feet of paper\0A\00"
@.str.5 = [37 x i8] c"They should order %d feet of ribbon\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %72
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = call i64 @fscanf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %64, label %27
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %15
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %72
27: ; preds = %19, %27
%28 = phi i32 [ %60, %27 ], [ 0, %19 ]
%29 = phi i32 [ %42, %27 ], [ 0, %19 ]
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = mul nsw i32 %31, %30
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, %31
%35 = mul nsw i32 %33, %30
%36 = call i64 @min(i32 %32, i32 %34, i32 %35)
%37 = trunc i64 %36 to i32
%38 = add i32 %34, %32
%39 = add i32 %38, %35
%40 = shl i32 %39, 1
%41 = add i32 %29, %37
%42 = add i32 %41, %40
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = add nsw i32 %44, %43
%46 = shl nsw i32 %45, 1
%47 = load i32, i32* %5
%48 = add nsw i32 %47, %44
%49 = shl nsw i32 %48, 1
%50 = add nsw i32 %47, %43
%51 = shl nsw i32 %50, 1
%52 = call i64 @min(i32 %46, i32 %49, i32 %51)
%53 = trunc i64 %52 to i32
%54 = add i32 %28, %53
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = mul nsw i32 %56, %55
%58 = load i32, i32* %5
%59 = mul nsw i32 %57, %58
%60 = add nsw i32 %54, %59
%61 = call i64 @fscanf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%62 = load i64, i64* @EOF
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %27
64: ; preds = %27, %19
%65 = phi i32 [ 0, %19 ], [ %42, %27 ]
%66 = phi i32 [ 0, %19 ], [ %60, %27 ]
%67 = load i32, i32* @stdout
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%69 = load i32, i32* @stdout
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%71 = call i32 @fclose(i32* %17)
br label %72
72: ; preds = %64, %23, %10
%73 = phi i32 [ 0, %10 ], [ 0, %64 ], [ 1, %23 ]
ret i32 %73
}