#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
main() {
  int sum = 0;
  int valid_input;
  char inbuf[133];
  char values[10];
  int i;
  for (i = 0; i < 10; i++) {
    valid_input = 0;
    while (!valid_input) {
      printf("Enter integer #%d: ", i + 1);
      gets(inbuf);
      printf("i=%d &values = %p &values[i] = %p\n", i, values, values + 1);
      valid_input = sscanf(inbuf, "%d", &values[i]);
      switch (valid_input) {
      case -1:
        printf("Please enter an integer.\n\n");
        valid_input = 0;
        break;
      case 0:
        printf("That was not an integer - please try again.\n\n");
      }
    }
  }
  for (i = 0; i < 10; i++)
    sum += values[i];
  printf("Averate is %.1f\n", (float)sum / (float)10);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xb0(%rbp)
cmpl   $0xa,-0xb0(%rbp)
jge    1268 <main+0x138>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117d <main+0x4d>
jmp    124f <main+0x11f>
mov    -0xb0(%rbp),%esi
add    $0x1,%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xc1(%rbp)
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    %rdi,-0xc0(%rbp)
call   1040 <gets@plt>
mov    -0xc1(%rbp),%al
mov    -0xb0(%rbp),%esi
lea    -0xa9(%rbp),%rcx
lea    0xe51(%rip),%rdi
lea    -0xaa(%rbp),%rdx
call   1030 <printf@plt>
mov    -0xc0(%rbp),%rdi
movslq -0xb0(%rbp),%rax
lea    -0xaa(%rbp,%rax,1),%rdx
ff
lea    0xe4b(%rip),%rsi
call   1050 <sscanf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0xb4(%rbp)
sub    $0xffffffff,%eax
je     1222 <main+0xf2>
jmp    120f <main+0xdf>
mov    -0xb4(%rbp),%eax
test   %eax,%eax
je     123c <main+0x10c>
jmp    124a <main+0x11a>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    124a <main+0x11a>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1167 <main+0x37>
jmp    1254 <main+0x124>
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
jmp    1153 <main+0x23>
movl   $0x0,-0xb0(%rbp)
cmpl   $0xa,-0xb0(%rbp)
jge    12a8 <main+0x178>
movslq -0xb0(%rbp),%rax
movsbl -0xaa(%rbp,%rax,1),%eax
ff
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
jmp    1272 <main+0x142>
cvtsi2ssl -0x8(%rbp),%xmm0
movss  0xd4b(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0x10(%rsp),%rbx
lea    0xede(%rip),%rbp
lea    0xf18(%rip),%r13
xor    %r15d,%r15d
jmp    1176 <main+0x36>
nopl   0x0(%rax)
cmp    $0xa,%r15
je     11ea <main+0xaa>
mov    %r15,%r14
add    $0x1,%r15
lea    (%rsp,%r14,1),%r12
jmp    1195 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
lea    0xe63(%rip),%rdi
mov    %r14d,%esi
mov    %rsp,%rdx
lea    0x1(%rsp),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
mov    %r13,%rdi
cmp    $0xffffffff,%eax
je     1190 <main+0x50>
test   %eax,%eax
jne    1170 <main+0x30>
lea    0xe67(%rip),%rdi
jmp    1190 <main+0x50>
movq   (%rsp),%xmm0
punpcklbw %xmm0,%xmm0
punpckhwd %xmm0,%xmm1
psrad  $0x18,%xmm1
punpcklwd %xmm0,%xmm0
psrad  $0x18,%xmm0
paddd  %xmm1,%xmm0
movsbl 0x8(%rsp),%eax
movsbl 0x9(%rsp),%ecx
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
add    %eax,%edx
add    %ecx,%edx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
divss  0xdc4(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter integer #%d: \00"
@.str.1 = [35 x i8] c"i=%d &values = %p &values[i] = %p\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Please enter an integer.\0A\0A\00"
@.str.4 = [46 x i8] c"That was not an integer - please try again.\0A\0A\00"
@.str.5 = [17 x i8] c"Averate is %.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [133 x i8]
%5 = alloca [10 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %6
br label %7
7: ; preds = %38, %0
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %41
10: ; preds = %7
store i32 0, i32* %3
br label %11
11: ; preds = %36, %10
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [133 x i8], [133 x i8]* %4, i64 0, i64 0
%20 = call i32 @gets(i8* %19)
%21 = load i32, i32* %6
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %22, i8* %24)
%26 = getelementptr inbounds [133 x i8], [133 x i8]* %4, i64 0, i64 0
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %28
%30 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
switch i32 %31, label %36 [
i32 -1, label %32
i32 0, label %34
]
32: ; preds = %15
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %36
34: ; preds = %15
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %15, %32
br label %11
37: ; preds = %11
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %7
41: ; preds = %7
store i32 0, i32* %6
br label %42
42: ; preds = %53, %41
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 10
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i32, i32* %2
%52 = add nsw i32 %51, %50
store i32 %52, i32* %2
br label %53
53: ; preds = %45
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %42
56: ; preds = %42
%57 = load i32, i32* %2
%58 = sitofp i32 %57 to float
%59 = fdiv float %58, 1.000000e+01
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), double %60)
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter integer #%d: \00"
@.str.1 = [35 x i8] c"i=%d &values = %p &values[i] = %p\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [17 x i8] c"Averate is %.1f\0A\00"
@str = [45 x i8] c"That was not an integer - please try again.\0A\00"
@str.6 = [26 x i8] c"Please enter an integer.\0A\00"
define i32 @main() {
%1 = alloca [133 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [133 x i8], [133 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
br label %6
6: ; preds = %0, %21
%7 = phi i64 [ 0, %0 ], [ %8, %21 ]
%8 = add nuw nsw i64 %7, 1
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %7
%10 = trunc i64 %8 to i32
%11 = trunc i64 %7 to i32
br label %12
12: ; preds = %18, %6
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %10)
%14 = call i32 @gets(i8* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* %4, i8* %5)
%16 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
switch i32 %16, label %21 [
i32 -1, label %18
i32 0, label %17
]
17: ; preds = %12
br label %18
18: ; preds = %12, %17
%19 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0), %17 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0), %12 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
br label %12
21: ; preds = %12
%22 = icmp eq i64 %8, 10
br i1 %22, label %23, label %6
23: ; preds = %21
%24 = bitcast [10 x i8]* %2 to <8 x i8>*
%25 = load <8 x i8>, <8 x i8>* %24
%26 = sext <8 x i8> %25 to <8 x i32>
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %26)
%34 = add nsw i32 %33, %29
%35 = add nsw i32 %34, %32
%36 = sitofp i32 %35 to float
%37 = fdiv float %36, 1.000000e+01
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), double %38)
ret i32 0
}