#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 EXIT_SUCCESS;
double M_PI;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, double *, double *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  FILE *input_file;
  FILE *data_out;
  input_file = fopen("lab4sample.dat", "r");
  data_out = fopen("lab4.out", "w");
  if ("lab4sample.dat" == NULL) {
    printf("Error on opening the input file \n");
    exit(EXIT_FAILURE);
  }
  if ("lab4.out" == NULL) {
    printf("Error on opening the output file \n");
    exit(EXIT_FAILURE);
  }
  fprintf(data_out, "\nMarc Woodyard.  Lab 4.  \n");
  int count = 1;
  double radius;
  double height;
  double area;
  double vol;
  while ((fscanf(input_file, "%lf%lf", &radius, &height)) == 2) {
    fprintf(data_out, "\nCylinder %1d", count);
    fprintf(data_out, "\nThe radius is:    %9.3f", radius);
    fprintf(data_out, "\nThe height is:    %9.3f", height);
    area = M_PI * radius * radius;
    fprintf(data_out, "\nThe top area is:  %9.3f", area);
    vol = M_PI * radius * radius * height;
    fprintf(data_out, "\nThe volume is:    %9.3f\n", vol);
    count++;
  }
  fclose(input_file);
  fclose(data_out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xea4(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    126f <main+0x12f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
lea    0xe70(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xe72(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2de7(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xe5a(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2db6(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
lea    0xe3d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <main+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%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
lea    0xe9b(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe96(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xe8d(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    1292 <main+0x142>
mov    $0x1,%ebp
mov    0x2e17(%rip),%r13
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe54(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
lea    0xe49(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
lea    0xe4b(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x0(%r13),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mov    %rbx,%rdi
lea    0xe3f(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x0(%r13),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
lea    0xe2d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%ebp
mov    %r14,%rdi
lea    0xdb9(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     11e0 <main+0x90>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"lab4sample.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"lab4.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [27 x i8] c"\0AMarc Woodyard. Lab 4. \0A\00"
@.str.5 = [7 x i8] c"%lf%lf\00"
@.str.6 = [14 x i8] c"\0ACylinder %1d\00"
@.str.7 = [25 x i8] c"\0AThe radius is: %9.3f\00"
@.str.8 = [25 x i8] c"\0AThe height is: %9.3f\00"
@M_PI = global double 0.000000e+00
@.str.9 = [25 x i8] c"\0AThe top area is: %9.3f\00"
@.str.10 = [26 x i8] c"\0AThe volume is: %9.3f\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %4
br label %13
13: ; preds = %17, %0
%14 = load i32*, i32** %2
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double* %5, double* %6)
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load i32*, i32** %3
%19 = load i32, i32* %4
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %3
%22 = load double, double* %5
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), double %22)
%24 = load i32*, i32** %3
%25 = load double, double* %6
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %25)
%27 = load double, double* @M_PI
%28 = load double, double* %5
%29 = fmul double %27, %28
%30 = load double, double* %5
%31 = fmul double %29, %30
store double %31, double* %7
%32 = load i32*, i32** %3
%33 = load double, double* %7
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), double %33)
%35 = load double, double* @M_PI
%36 = load double, double* %5
%37 = fmul double %35, %36
%38 = load double, double* %5
%39 = fmul double %37, %38
%40 = load double, double* %6
%41 = fmul double %39, %40
store double %41, double* %8
%42 = load i32*, i32** %3
%43 = load double, double* %8
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), double %43)
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %13
47: ; preds = %13
%48 = load i32*, i32** %2
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@.str = [15 x i8] c"lab4sample.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"lab4.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [27 x i8] c"\0AMarc Woodyard. Lab 4. \0A\00"
@.str.5 = [7 x i8] c"%lf%lf\00"
@.str.6 = [14 x i8] c"\0ACylinder %1d\00"
@.str.7 = [25 x i8] c"\0AThe radius is: %9.3f\00"
@.str.8 = [25 x i8] c"\0AThe height is: %9.3f\00"
@M_PI = global double 0.000000e+00
@.str.9 = [25 x i8] c"\0AThe top area is: %9.3f\00"
@.str.10 = [26 x i8] c"\0AThe volume is: %9.3f\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i64 26, i64 1, i32* %4)
%6 = bitcast double* %1 to i8*
%7 = bitcast double* %2 to i8*
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double* %1, double* %2)
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %32
10: ; preds = %0, %10
%11 = phi i32 [ %29, %10 ], [ 1, %0 ]
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %11)
%13 = load double, double* %1
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), double %13)
%15 = load double, double* %2
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %15)
%17 = load double, double* @M_PI
%18 = load double, double* %1
%19 = fmul double %17, %18
%20 = fmul double %18, %19
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), double %20)
%22 = load double, double* @M_PI
%23 = load double, double* %1
%24 = fmul double %22, %23
%25 = fmul double %23, %24
%26 = load double, double* %2
%27 = fmul double %26, %25
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), double %27)
%29 = add nuw nsw i32 %11, 1
%30 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double* %1, double* %2)
%31 = icmp eq i32 %30, 2
br i1 %31, label %10, label %32
32: ; preds = %10, %0
%33 = call i32 @fclose(i32* %3)
%34 = call i32 @fclose(i32* %4)
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}