#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 *, double);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int i;
  int sum = 0;
  int grade;
  for (i = 0;; i++) {
    printf("输入第%d人的成绩:", i + 1);
    scanf("%d", &grade);
    if (grade == -1)
      break;
    sum = sum + grade;
  }
  printf("avg=%f\n", (double)sum / i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1172 <main+0x52>
jmp    1189 <main+0x69>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113d <main+0x1d>
cvtsi2sdl -0xc(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
mov    $0xffffffff,%ebx
lea    0xec5(%rip),%r14
lea    0xed7(%rip),%r15
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %eax,%r13d
lea    0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ecx
lea    (%rcx,%r13,1),%eax
add    $0x1,%ebx
cmp    $0xffffffff,%ecx
jne    1150 <main+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\E8\BE\93\E5\85\A5\E7\AC\AC%d\E4\BA\BA\E7\9A\84\E6\88\90\E7\BB\A9:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"avg=%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %2
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
%8 = sitofp i32 %7 to double
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %8)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %5
br label %21
14: ; preds = %5
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
store i32 %17, i32* %3
br label %18
18: ; preds = %14
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %5
21: ; preds = %13
%22 = load i32, i32* %3
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [25 x i8] c"\E8\BE\93\E5\85\A5\E7\AC\AC%d\E4\BA\BA\E7\9A\84\E6\88\90\E7\BB\A9:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"avg=%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 0, %0 ], [ %6, %3 ]
%5 = phi i32 [ 0, %0 ], [ %12, %3 ]
%6 = add nuw nsw i32 %4, 1
%7 = sitofp i32 %6 to double
%8 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %7)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, -1
%12 = add nsw i32 %10, %5
br i1 %11, label %13, label %3
13: ; preds = %3
%14 = sitofp i32 %5 to double
%15 = sitofp i32 %4 to double
%16 = fdiv double %14, %15
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %16)
ret i32 0
}