#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 *, int, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main() {
  FILE *file = fopen("/home/transvaal/Documents/Ctest2.txt", "w");
  int studentCount;
  printf("How many students are there?\n");
  scanf("%i", &studentCount);
  fprintf(file, "%i\n", studentCount);
  for (int i = 0; i < studentCount; i++) {
    char studentName[30] = {0};
    float gpa;
    printf("What is the student's last name?\n");
    scanf("%s", studentName);
    printf("What is the student's GPA?\n");
    scanf("%f", &gpa);
    fprintf(file, "%i %s %.2f\n", strlen(studentName), studentName, gpa);
  }
  printf("File generated succesfully.\n");
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1268 <main+0xf8>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1060 <memset@plt>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    -0x40(%rbp),%rcx
movss  -0x44(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3d(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d0 <main+0x60>
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe8b(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe90(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x8(%rsp),%edx
lea    0xe7c(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1252 <main+0xf2>
lea    0x10(%rsp),%rbx
lea    0xe62(%rip),%rbp
lea    0xc(%rsp),%r14
lea    0xe59(%rip),%r15
xor    %r13d,%r13d
xchg   %ax,%ax
xorps  %xmm0,%xmm0
movups %xmm0,0x1e(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r13d
cmp    0x8(%rsp),%r13d
jl     11e0 <main+0x80>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"/home/transvaal/Documents/Ctest2.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [30 x i8] c"How many students are there?\0A\00"
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [4 x i8] c"%i\0A\00"
@.str.5 = [34 x i8] c"What is the student's last name?\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [28 x i8] c"What is the student's GPA?\0A\00"
@.str.8 = [3 x i8] c"%f\00"
@.str.9 = [12 x i8] c"%i %s %.2f\0A\00"
@.str.10 = [29 x i8] c"File generated succesfully.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = alloca float
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%10 = load i32*, i32** %2
%11 = load i32, i32* %3
%12 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %11)
store i32 0, i32* %4
br label %13
13: ; preds = %31, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = bitcast [30 x i8]* %5 to i8*
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %6)
%24 = load i32*, i32** %2
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%28 = load float, float* %6
%29 = fpext float %28 to double
%30 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %26, i8* %27, double %29)
br label %31
31: ; preds = %17
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %13
34: ; preds = %13
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"/home/transvaal/Documents/Ctest2.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [4 x i8] c"%i\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.8 = [3 x i8] c"%f\00"
@.str.9 = [12 x i8] c"%i %s %.2f\0A\00"
@str = [29 x i8] c"How many students are there?\00"
@str.11 = [28 x i8] c"File generated succesfully.\00"
@str.12 = [33 x i8] c"What is the student's last name?\00"
@str.13 = [27 x i8] c"What is the student's GPA?\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca float
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%14 = bitcast float* %3 to i8*
br label %18
15: ; preds = %18, %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%17 = call i32 @fclose(i32* %4)
ret i32 0
18: ; preds = %12, %18
%19 = phi i32 [ 0, %12 ], [ %28, %18 ]
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.12, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %3)
%24 = call i32 @strlen(i8* %13)
%25 = load float, float* %3
%26 = fpext float %25 to double
%27 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %24, i8* %13, double %26)
%28 = add nuw nsw i32 %19, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %28, %29
br i1 %30, label %18, label %15
}