#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() {
  int counter = 0;
  int sum = 0, num = 0;
  do {
    printf("Enter positive number (negative to quit): ");
    scanf("%d", &num);
    if (num < 0)
      continue;
    sum += num;
    ++counter;
  } while (num >= 0);
  printf("Average: %f\n", (double)sum / (double)counter);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    1171 <main+0x51>
jmp    1183 <main+0x63>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1144 <main+0x24>
cvtsi2sdl -0xc(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
xor    %r12d,%r12d
lea    0xec3(%rip),%r14
lea    0xee7(%rip),%r15
lea    0x4(%rsp),%r13
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
xor    %ecx,%ecx
test   %eax,%eax
mov    %eax,%edx
cmovs  %r12d,%edx
setns  %cl
add    %ecx,%ebp
add    %edx,%ebx
test   %eax,%eax
jns    1150 <main+0x30>
cvtsi2sd %ebx,%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xe9d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Enter positive number (negative to quit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Average: %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* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %17, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %5
br label %17
11: ; preds = %5
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = add nsw i32 %13, %12
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %17
17: ; preds = %11, %10
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 0
br i1 %19, label %5, label %20
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = load i32, i32* %2
%24 = sitofp i32 %23 to double
%25 = fdiv double %22, %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [43 x i8] c"Enter positive number (negative to quit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Average: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 0, %0 ], [ %12, %3 ]
%5 = phi i32 [ 0, %0 ], [ %14, %3 ]
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %4, %11
%13 = select i1 %9, i32 0, i32 %8
%14 = add nuw nsw i32 %13, %5
%15 = icmp sgt i32 %8, -1
br i1 %15, label %3, label %16
16: ; preds = %3
%17 = sitofp i32 %14 to double
%18 = sitofp i32 %12 to double
%19 = fdiv double %17, %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %19)
ret i32 0
}