#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int a[100], i, th, n, count = 0, sum, temp;
  printf("Array size : ");
  scanf("%d", &n);
  printf("Elements to Array : ");
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  printf("Array   elements  : ");
  for (i = 0; i < n; i++)
    printf("%d ", a[i]);
  printf("\nThreshold value   : ");
  scanf("%d", &th);
  for (i = 0; i < n; i++) {
    temp = th;
    sum = 0;
    while (sum != a[i]) {
      sum += temp;
      count++;
      if (sum > a[i]) {
        sum -= temp;
        temp--;
        count--;
      }
    }
  }
  printf("count = %d\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1b0(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x1ac(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x1ac(%rbp),%eax
jge    11bc <main+0x9c>
movslq -0x1a4(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6b(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1175 <main+0x55>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x1ac(%rbp),%eax
jge    1216 <main+0xf6>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11d4 <main+0xb4>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde3(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0x1ac(%rbp),%eax
jge    130e <main+0x1ee>
mov    -0x1a8(%rbp),%eax
mov    %eax,-0x1b8(%rbp)
movl   $0x0,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
movslq -0x1a4(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
je     12f5 <main+0x1d5>
mov    -0x1b8(%rbp),%eax
add    -0x1b4(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1b4(%rbp),%eax
movslq -0x1a4(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jle    12f0 <main+0x1d0>
mov    -0x1b8(%rbp),%ecx
mov    -0x1b4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1b8(%rbp)
mov    -0x1b0(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1b0(%rbp)
jmp    1269 <main+0x149>
jmp    12fa <main+0x1da>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1241 <main+0x121>
mov    -0x1b0(%rbp),%esi
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    118d <main+0x6d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xea0(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1170 <main+0x50>
lea    0xe92(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11cd <main+0xad>
lea    0xe90(%rip),%r14
xor    %r15d,%r15d
xchg   %ax,%ax
mov    0x10(%rsp,%r15,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r15
movslq 0x8(%rsp),%rax
cmp    %rax,%r15
jl     11b0 <main+0x90>
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe2c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%r9d
test   %r9d,%r9d
jle    1251 <main+0x131>
xor    %r10d,%r10d
mov    0xc(%rsp),%r8d
xor    %ebx,%ebx
jmp    1219 <main+0xf9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r10
cmp    %r9,%r10
je     1251 <main+0x131>
mov    0x10(%rsp,%r10,4),%r11d
test   %r11d,%r11d
je     1210 <main+0xf0>
xor    %edx,%edx
mov    %r8d,%edi
nopl   0x0(%rax,%rax,1)
lea    (%rdi,%rdx,1),%eax
xor    %ecx,%ecx
xor    %esi,%esi
cmp    %r11d,%eax
setg   %cl
cmovg  %edx,%eax
setle  %sil
add    %esi,%ebx
sub    %ecx,%edi
mov    %eax,%edx
cmp    %r11d,%eax
jne    1230 <main+0x110>
jmp    1210 <main+0xf0>
lea    0xdfd(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"Array size : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Elements to Array : \00"
@.str.3 = [21 x i8] c"Array elements : \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [22 x i8] c"\0AThreshold value : \00"
@.str.6 = [12 x i8] c"count = %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [100 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %20, %24
%25 = phi i64 [ %29, %24 ], [ 0, %20 ]
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %25, 1
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %24, label %33
33: ; preds = %24, %20
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %64
38: ; preds = %33
%39 = load i32, i32* %2
%40 = zext i32 %36 to i64
br label %41
41: ; preds = %38, %60
%42 = phi i64 [ 0, %38 ], [ %62, %60 ]
%43 = phi i32 [ 0, %38 ], [ %61, %60 ]
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %42
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %60, label %47
47: ; preds = %41, %47
%48 = phi i32 [ %58, %47 ], [ %39, %41 ]
%49 = phi i32 [ %56, %47 ], [ 0, %41 ]
%50 = phi i32 [ %55, %47 ], [ %43, %41 ]
%51 = add nsw i32 %48, %49
%52 = icmp sgt i32 %51, %45
%53 = xor i1 %52, true
%54 = zext i1 %53 to i32
%55 = add nsw i32 %50, %54
%56 = select i1 %52, i32 %49, i32 %51
%57 = sext i1 %52 to i32
%58 = add nsw i32 %48, %57
%59 = icmp eq i32 %56, %45
br i1 %59, label %60, label %47
60: ; preds = %47, %41
%61 = phi i32 [ %43, %41 ], [ %55, %47 ]
%62 = add nuw nsw i64 %42, 1
%63 = icmp eq i64 %62, %40
br i1 %63, label %64, label %41
64: ; preds = %60, %33
%65 = phi i32 [ 0, %33 ], [ %61, %60 ]
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %65)
ret i32 0
}