#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);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int i = 1, soma = 0, num = 0, idade;
  do {
    printf("Digite a idade #%d: ", i);
    i++;
    scanf(" %d", &idade);
    if (idade != 0) {
      soma += idade;
      num++;
    }
  } while (idade != 0);
  printf("\nMedia das idades entradas: %d.\n", soma / num);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
je     1181 <main+0x61>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <main+0x66>
cmpl   $0x0,-0x10(%rbp)
jne    113d <main+0x1d>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
mov    $0x1,%ebx
lea    0xec6(%rip),%r14
lea    0xed4(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
add    %eax,%ebp
test   %eax,%eax
jne    1150 <main+0x30>
add    $0xfffffffe,%ebx
mov    %ebp,%eax
cltd
idiv   %ebx
lea    0xe98(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Digite a idade #%d: \00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [33 x i8] c"\0AMedia das idades entradas: %d.\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %5
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %14
store i32 %16, i32* %2
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %13, %5
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = sdiv i32 %24, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Digite a idade #%d: \00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [33 x i8] c"\0AMedia das idades entradas: %d.\0A\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 1, %0 ], [ %8, %3 ]
%5 = phi i32 [ 0, %0 ], [ %12, %3 ]
%6 = phi i32 [ 0, %0 ], [ %13, %3 ]
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = add nuw nsw i32 %4, 1
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
%12 = add nsw i32 %10, %5
%13 = add nuw nsw i32 %6, 1
br i1 %11, label %14, label %3
14: ; preds = %3
%15 = sdiv i32 %12, %6
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %15)
ret void
}