#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 */
char EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  int n, i;
  char name[30], ch;
  long int prn;
  float marks;
  FILE *fp = fopen("student_details.txt", "a+");
  if (fp == NULL) {
    printf("cant open file");
    exit(0);
  }
  printf("Enter no of students: ");
  scanf("%d%*c", &n);
  for (i = 0; i < n; ++i) {
    printf("Enter student name %d: ", i + 1);
    fgets(name, 30, stdin);
    printf("Enter student prn %d: ", i + 1);
    scanf("%ld%*c", &prn);
    printf("Enter student marks %d: ", i + 1);
    scanf("%f%*c", &marks);
    fprintf(fp, "\n\nName:%s", name);
    fprintf(fp, "PRN:%ld", prn);
    fprintf(fp, "\nMarks:%f", marks);
  }
  rewind(fp);
  printf("----------------------------------------\n");
  printf("Content of the file\n");
  while ((ch = getc(fp)) != EOF)
    printf("%c", ch);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11d6 <main+0x46>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d5 <main+0x145>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe23(%rip),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1d(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rdi
movss  -0x44(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdea(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fd <main+0x6d>
mov    -0x50(%rbp),%rdi
call   1050 <rewind@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
mov    0x2cd0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1332 <main+0x1a2>
movsbl -0x31(%rbp),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fa <main+0x16a>
mov    -0x50(%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    0xe3b(%rip),%rdi
lea    0xe48(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     134e <main+0x19e>
mov    %rax,%rbx
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    12e6 <main+0x136>
lea    0x10(%rsp),%r15
lea    0xe86(%rip),%rbp
lea    0xe89(%rip),%r14
lea    0xe8a(%rip),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13d
lea    0xe08(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x1e,%esi
call   1080 <fgets@plt>
lea    0xdf9(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdff(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
lea    0xdf3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
cmp    (%rsp),%r13d
jl     1230 <main+0x80>
mov    %rbx,%rdi
call   1070 <rewind@plt>
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10d0 <getc@plt>
mov    0x2ccb(%rip),%rbp
cmp    0x0(%rbp),%al
je     1335 <main+0x185>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   10d0 <getc@plt>
cmp    0x0(%rbp),%al
jne    1320 <main+0x170>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"student_details.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [15 x i8] c"cant open file\00"
@.str.3 = [23 x i8] c"Enter no of students: \00"
@.str.4 = [6 x i8] c"%d%*c\00"
@.str.5 = [24 x i8] c"Enter student name %d: \00"
@stdin = global i32 0
@.str.6 = [23 x i8] c"Enter student prn %d: \00"
@.str.7 = [7 x i8] c"%ld%*c\00"
@.str.8 = [25 x i8] c"Enter student marks %d: \00"
@.str.9 = [6 x i8] c"%f%*c\00"
@.str.10 = [10 x i8] c"\0A\0AName:%s\00"
@.str.11 = [8 x i8] c"PRN:%ld\00"
@.str.12 = [10 x i8] c"\0AMarks:%f\00"
@.str.13 = [42 x i8] c"----------------------------------------\0A\00"
@.str.14 = [21 x i8] c"Content of the file\0A\00"
@EOF = global i8 0
@.str.15 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = alloca i8
%6 = alloca i64
%7 = alloca float
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %18
18: ; preds = %47, %15
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %26, i32 30, i32 %27)
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i64* %6)
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %34)
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), float* %7)
%37 = load i32*, i32** %8
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %8
%41 = load i64, i64* %6
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i64 %41)
%43 = load i32*, i32** %8
%44 = load float, float* %7
%45 = fpext float %44 to double
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), double %45)
br label %47
47: ; preds = %22
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %18
50: ; preds = %18
%51 = load i32*, i32** %8
%52 = call i32 @rewind(i32* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0))
br label %55
55: ; preds = %62, %50
%56 = load i32*, i32** %8
%57 = call signext i8 @getc(i32* %56)
store i8 %57, i8* %5
%58 = sext i8 %57 to i32
%59 = load i8, i8* @EOF
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i8, i8* %5
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32 %64)
br label %55
66: ; preds = %55
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"student_details.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [15 x i8] c"cant open file\00"
@.str.3 = [23 x i8] c"Enter no of students: \00"
@.str.4 = [6 x i8] c"%d%*c\00"
@.str.5 = [24 x i8] c"Enter student name %d: \00"
@stdin = global i32 0
@.str.6 = [23 x i8] c"Enter student prn %d: \00"
@.str.7 = [7 x i8] c"%ld%*c\00"
@.str.8 = [25 x i8] c"Enter student marks %d: \00"
@.str.9 = [6 x i8] c"%f%*c\00"
@.str.10 = [10 x i8] c"\0A\0AName:%s\00"
@.str.11 = [8 x i8] c"PRN:%ld\00"
@.str.12 = [10 x i8] c"\0AMarks:%f\00"
@EOF = global i8 0
@str = [41 x i8] c"----------------------------------------\00"
@str.16 = [20 x i8] c"Content of the file\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i64
%4 = alloca float
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%7 = bitcast i64* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %14, %19
%20 = phi i32 [ %21, %19 ], [ 0, %14 ]
%21 = add nuw nsw i32 %20, 1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %6, i32 30, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i64* %3)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %21)
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), float* %4)
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %6)
%30 = load i64, i64* %3
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i64 %30)
%32 = load float, float* %4
%33 = fpext float %32 to double
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), double %33)
%35 = load i32, i32* %1
%36 = icmp slt i32 %21, %35
br i1 %36, label %19, label %37
37: ; preds = %19, %14
%38 = call i32 @rewind(i32* %9)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%41 = call signext i8 @getc(i32* %9)
%42 = load i8, i8* @EOF
%43 = icmp eq i8 %41, %42
br i1 %43, label %51, label %44
44: ; preds = %37, %44
%45 = phi i8 [ %48, %44 ], [ %41, %37 ]
%46 = sext i8 %45 to i32
%47 = call i32 @putchar(i32 %46)
%48 = call signext i8 @getc(i32* %9)
%49 = load i8, i8* @EOF
%50 = icmp eq i8 %48, %49
br i1 %50, label %51, label %44
51: ; preds = %44, %37
%52 = call i32 @fclose(i32* %9)
ret i32 0
}