#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 count = 0, num, total = 0;
  printf("Please enter some integers (negative to stop) -- ");
  scanf("%i", &num);
  while (num >= 0) {
    total = total + num;
    count = count + 1;
    scanf("%i", &num);
  }
  printf("Entered %i numbers.\n", count);
  printf("Total was %i.\n", total);
  printf("Average was %i.\n", total / count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jl     118c <main+0x6c>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xeb4(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    115b <main+0x3b>
mov    -0x8(%rbp),%esi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    $0x0,%ebp
test   %eax,%eax
js     1188 <main+0x68>
xor    %ebp,%ebp
lea    0xed4(%rip),%r14
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    %eax,%ebp
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jns    1170 <main+0x50>
lea    0xea6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
lea    0xea5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Please enter some integers (negative to stop) -- \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [21 x i8] c"Entered %i numbers.\0A\00"
@.str.3 = [15 x i8] c"Total was %i.\0A\00"
@.str.4 = [17 x i8] c"Average was %i.\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* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 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* %3)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = add nsw i32 %11, %12
store i32 %13, i32* %4
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %7
17: ; preds = %7
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = sdiv i32 %22, %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [50 x i8] c"Please enter some integers (negative to stop) -- \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [21 x i8] c"Entered %i numbers.\0A\00"
@.str.3 = [15 x i8] c"Total was %i.\0A\00"
@.str.4 = [17 x i8] c"Average was %i.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ %5, %0 ]
%9 = phi i32 [ %11, %7 ], [ 0, %0 ]
%10 = phi i32 [ %12, %7 ], [ 0, %0 ]
%11 = add nsw i32 %8, %9
%12 = add nuw nsw i32 %10, 1
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, -1
br i1 %15, label %7, label %16
16: ; preds = %7, %0
%17 = phi i32 [ 0, %0 ], [ %12, %7 ]
%18 = phi i32 [ 0, %0 ], [ %11, %7 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%21 = sdiv i32 %18, %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %21)
ret i32 0
}