#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void write(char filename2[], char name[][40], float w[], float q[], float t[],
           float p[], float e[], float total[], char grade[][3]) {
  FILE *fp = fopen(filename2, "w+");
  if (fp != NULL) {
    int i;
    fprintf(fp, "                                        Table 1               "
                "                     \n");
    fprintf(fp, "  Student Name         W(30%%)   Q(15%%)   T(20%%)   P(15%%)  "
                " E(20%%)   TOTAL   GRADE \n");
    for (i = 0; i < 100; i++) {
      fprintf(fp,
              "  %-18s   %-6.0f   %-6.0f   %-6.0f   %-6.0f   %-6.0f   %-6.2f   "
              " %-4s  \n",
              name[i], w[i], q[i], t[i], p[i], e[i], total[i], grade[i]);
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     125d <write+0x12d>
mov    -0x38(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xec0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x64,-0x3c(%rbp)
jge    1254 <write+0x124>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x3c(%rbp),%rax
imul   $0x28,%rax,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
cvtss2sd %xmm2,%xmm2
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm3
cvtss2sd %xmm3,%xmm3
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm4
cvtss2sd %xmm4,%xmm4
mov    0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm5
cvtss2sd %xmm5,%xmm5
mov    0x20(%rbp),%rcx
movslq -0x3c(%rbp),%rax
imul   $0x3,%rax,%rax
add    %rax,%rcx
lea    0xe72(%rip),%rsi
mov    $0x6,%al
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a6 <write+0x76>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r15
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x80(%rsp),%rbp
mov    0x78(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x70(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0xe80(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1271 <write+0x131>
lea    0xe69(%rip),%rdi
mov    $0x54,%esi
mov    $0x1,%edx
mov    %r15,0x20(%rsp)
mov    0x8(%rsp),%r15
mov    %r15,%rcx
call   1060 <fwrite@plt>
lea    0xe9b(%rip),%rsi
mov    %r12,0x30(%rsp)
mov    %r13,0x28(%rsp)
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x18(%rsp),%r12
mov    0x10(%rsp),%r15
xchg   %ax,%ax
movss  (%r14,%r13,1),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x30(%rsp),%rax
movss  (%rax,%r13,1),%xmm1
cvtss2sd %xmm1,%xmm1
mov    0x28(%rsp),%rax
movss  (%rax,%r13,1),%xmm2
cvtss2sd %xmm2,%xmm2
mov    0x20(%rsp),%rax
movss  (%rax,%r13,1),%xmm3
cvtss2sd %xmm3,%xmm3
movss  (%r15,%r13,1),%xmm4
cvtss2sd %xmm4,%xmm4
movss  (%r12,%r13,1),%xmm5
cvtss2sd %xmm5,%xmm5
mov    0x8(%rsp),%rdi
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    $0x6,%al
call   1040 <fprintf@plt>
add    $0x4,%r13
add    $0x28,%rbx
add    $0x3,%rbp
cmp    $0x190,%r13
jne    11e0 <write+0xa0>
mov    0x8(%rsp),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [85 x i8] c" Table 1 \0A\00"
@.str.2 = [89 x i8] c" Student Name W(30%%) Q(15%%) T(20%%) P(15%%) E(20%%) TOTAL GRADE \0A\00"
@.str.3 = [73 x i8] c" %-18s %-6.0f %-6.0f %-6.0f %-6.0f %-6.0f %-6.2f %-4s \0A\00"
define void @write(i8* %0, [40 x i8]* %1, float* %2, float* %3, float* %4, float* %5, float* %6, float* %7, [3 x i8]* %8) {
%10 = alloca i8*
%11 = alloca [40 x i8]*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca [3 x i8]*
%19 = alloca i32*
%20 = alloca i32
store i8* %0, i8** %10
store [40 x i8]* %1, [40 x i8]** %11
store float* %2, float** %12
store float* %3, float** %13
store float* %4, float** %14
store float* %5, float** %15
store float* %6, float** %16
store float* %7, float** %17
store [3 x i8]* %8, [3 x i8]** %18
%21 = load i8*, i8** %10
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %19
%23 = load i32*, i32** %19
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %88
25: ; preds = %9
%26 = load i32*, i32** %19
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32*, i32** %19
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %20
br label %30
30: ; preds = %82, %25
%31 = load i32, i32* %20
%32 = icmp slt i32 %31, 100
br i1 %32, label %33, label %85
33: ; preds = %30
%34 = load i32*, i32** %19
%35 = load [40 x i8]*, [40 x i8]** %11
%36 = load i32, i32* %20
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %35, i64 %37
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %38, i64 0, i64 0
%40 = load float*, float** %12
%41 = load i32, i32* %20
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %40, i64 %42
%44 = load float, float* %43
%45 = fpext float %44 to double
%46 = load float*, float** %13
%47 = load i32, i32* %20
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = load float, float* %49
%51 = fpext float %50 to double
%52 = load float*, float** %14
%53 = load i32, i32* %20
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %52, i64 %54
%56 = load float, float* %55
%57 = fpext float %56 to double
%58 = load float*, float** %15
%59 = load i32, i32* %20
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %58, i64 %60
%62 = load float, float* %61
%63 = fpext float %62 to double
%64 = load float*, float** %16
%65 = load i32, i32* %20
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %64, i64 %66
%68 = load float, float* %67
%69 = fpext float %68 to double
%70 = load float*, float** %17
%71 = load i32, i32* %20
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds float, float* %70, i64 %72
%74 = load float, float* %73
%75 = fpext float %74 to double
%76 = load [3 x i8]*, [3 x i8]** %18
%77 = load i32, i32* %20
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [3 x i8], [3 x i8]* %76, i64 %78
%80 = getelementptr inbounds [3 x i8], [3 x i8]* %79, i64 0, i64 0
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i8* %39, double %45, double %51, double %57, double %63, double %69, double %75, i8* %80)
br label %82
82: ; preds = %33
%83 = load i32, i32* %20
%84 = add nsw i32 %83, 1
store i32 %84, i32* %20
br label %30
85: ; preds = %30
%86 = load i32*, i32** %19
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %85, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [85 x i8] c" Table 1 \0A\00"
@.str.2 = [89 x i8] c" Student Name W(30%%) Q(15%%) T(20%%) P(15%%) E(20%%) TOTAL GRADE \0A\00"
@.str.3 = [73 x i8] c" %-18s %-6.0f %-6.0f %-6.0f %-6.0f %-6.0f %-6.2f %-4s \0A\00"
define void @write(i8* nocapture %0, [40 x i8]* %1, float* nocapture %2, float* nocapture %3, float* nocapture %4, float* nocapture %5, float* nocapture %6, float* nocapture %7, [3 x i8]* %8) {
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %42, label %12
12: ; preds = %9
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0), i64 84, i64 1, i32* %10)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 0, %12 ], [ %38, %15 ]
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 %16, i64 0
%18 = getelementptr inbounds float, float* %2, i64 %16
%19 = load float, float* %18
%20 = fpext float %19 to double
%21 = getelementptr inbounds float, float* %3, i64 %16
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = getelementptr inbounds float, float* %4, i64 %16
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = getelementptr inbounds float, float* %5, i64 %16
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = getelementptr inbounds float, float* %6, i64 %16
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = getelementptr inbounds float, float* %7, i64 %16
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 %16, i64 0
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i8* %17, double %20, double %23, double %26, double %29, double %32, double %35, i8* %36)
%38 = add nuw nsw i64 %16, 1
%39 = icmp eq i64 %38, 100
br i1 %39, label %40, label %15
40: ; preds = %15
%41 = tail call i32 @fclose(i32* %10)
br label %42
42: ; preds = %40, %9
ret void
}