#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int bsize, n, i = 0;
  int *fsize;
  int start = 0, end = 0;
  printf("Enter memory block size\n");
  scanf("%d", &bsize);
  printf("Enter no of files\n");
  scanf("%d", &n);
  fsize = (int *)malloc(sizeof(int) * n);
  while (i < n) {
    printf("Enter size for File%d", i + 1);
    scanf("%d", &fsize[i++]);
  }
  for (i = 0; i < n; i++) {
    if (fsize[i] > bsize) {
      printf("Insufficient Memory");
      exit(1);
    } else {
      bsize = bsize - fsize[i];
      end = end + fsize[i] - 1;
      printf("Start for file%d is %d", i + 1, start);
      printf("End of file%d is %d\n", i + 1, end);
    }
    start = end + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <main+0xbc>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cltq
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe78(%rip),%rdi
call   1050 <scanf@plt>
jmp    11b3 <main+0x73>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a5 <main+0x165>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jle    123b <main+0xfb>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x10(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x1c(%rbp),%edx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%edx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1203 <main+0xc3>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
lea    0xed0(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
cmpl   $0x0,(%rsp)
jle    1257 <main+0x107>
mov    %rax,%r12
lea    0xe4f(%rip),%r14
lea    0xe86(%rip),%r15
mov    %rax,%r13
xor    %ebx,%ebx
nopl   (%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
movslq (%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11c0 <main+0x70>
test   %eax,%eax
jle    1257 <main+0x107>
lea    0xe37(%rip),%r14
lea    0xe47(%rip),%r15
xor    %ebx,%ebx
xor    %r13d,%r13d
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
sub    (%r12,%rbx,4),%eax
jl     1268 <main+0x118>
mov    %eax,0x4(%rsp)
mov    (%r12,%rbx,4),%eax
lea    (%rax,%r13,1),%ebp
add    %eax,%r13d
add    $0xffffffff,%r13d
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movslq (%rsp),%rax
mov    %ebp,%edx
cmp    %rax,%rbx
jl     1210 <main+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Enter memory block size\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter no of files\0A\00"
@.str.3 = [22 x i8] c"Enter size for File%d\00"
@.str.4 = [20 x i8] c"Insufficient Memory\00"
@.str.5 = [23 x i8] c"Start for file%d is %d\00"
@.str.6 = [21 x i8] c"End of file%d is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = mul i64 4, %13
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %5
br label %18
18: ; preds = %22, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %5
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %30)
br label %18
32: ; preds = %18
store i32 0, i32* %4
br label %33
33: ; preds = %75, %32
%34 = load i32, i32* %4
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %78
37: ; preds = %33
%38 = load i32*, i32** %5
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %2
%44 = icmp sgt i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %37
%49 = load i32, i32* %2
%50 = load i32*, i32** %5
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = sub nsw i32 %49, %54
store i32 %55, i32* %2
%56 = load i32, i32* %7
%57 = load i32*, i32** %5
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = add nsw i32 %56, %61
%63 = sub nsw i32 %62, 1
store i32 %63, i32* %7
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
%66 = load i32, i32* %6
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %65, i32 %66)
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %69, i32 %70)
br label %72
72: ; preds = %48
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %6
br label %75
75: ; preds = %72
%76 = load i32, i32* %4
%77 = add nsw i32 %76, 1
store i32 %77, i32* %4
br label %33
78: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"Enter size for File%d\00"
@.str.4 = [20 x i8] c"Insufficient Memory\00"
@.str.5 = [23 x i8] c"Start for file%d is %d\00"
@.str.6 = [21 x i8] c"End of file%d is %d\0A\00"
@str = [24 x i8] c"Enter memory block size\00"
@str.7 = [18 x i8] c"Enter no of files\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = shl i32 %9, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %17, label %50
15: ; preds = %17
%16 = icmp sgt i32 %24, 0
br i1 %16, label %27, label %50
17: ; preds = %0, %17
%18 = phi i64 [ %19, %17 ], [ 0, %0 ]
%19 = add nuw nsw i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i32, i32* %12, i64 %18
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %19, %25
br i1 %26, label %17, label %15
27: ; preds = %15, %38
%28 = phi i64 [ %43, %38 ], [ 0, %15 ]
%29 = phi i32 [ %42, %38 ], [ 0, %15 ]
%30 = phi i32 [ %41, %38 ], [ 0, %15 ]
%31 = getelementptr inbounds i32, i32* %12, i64 %28
%32 = load i32, i32* %31
%33 = load i32, i32* %1
%34 = icmp slt i32 %33, %32
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
%39 = sub nsw i32 %33, %32
store i32 %39, i32* %1
%40 = load i32, i32* %31
%41 = add nsw i32 %40, %29
%42 = add nsw i32 %41, -1
%43 = add nuw nsw i64 %28, 1
%44 = trunc i64 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %30)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %44, i32 %42)
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %43, %48
br i1 %49, label %27, label %50
50: ; preds = %38, %0, %15
ret i32 0
}