#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 */
double media(float *, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main() {
  int i;
  float notas[3];
  for (i = 0; i < 3; i++) {
    printf("Insira a nota %d: ", i);
    scanf("%f", &notas[i]);
  }
  printf("Insira 'P' se deseja media ponderada ou 'A' para media aritmetica: ");
  setbuf(stdin, NULL);
  char tipo;
  scanf("%c", &tipo);
  if (tipo == 'p' || tipo == 'P') {
    printf("A media ponderada: %.2f\n", media(notas, tipo));
  } else if (tipo == 'A' || tipo == 'a') {
    printf("A media aritmetica: %.2f\n", media(notas, tipo));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119c <main+0x5c>
mov    -0x8(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x8(%rbp),%rax
lea    -0x14(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x16>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
lea    0xe97(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x70,%eax
je     11e8 <main+0xa8>
movsbl -0x15(%rbp),%eax
cmp    $0x50,%eax
jne    1208 <main+0xc8>
lea    -0x14(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1060 <media@plt>
lea    0xe61(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1242 <main+0x102>
movsbl -0x15(%rbp),%eax
cmp    $0x41,%eax
je     1222 <main+0xe2>
movsbl -0x15(%rbp),%eax
cmp    $0x61,%eax
jne    123d <main+0xfd>
lea    -0x14(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1060 <media@plt>
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1242 <main+0x102>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb2(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
lea    0xe89(%rip),%rdi
lea    0xb(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xb(%rsp),%al
mov    %eax,%ecx
and    $0xdf,%cl
cmp    $0x50,%cl
je     11f9 <main+0xb9>
cmp    $0x41,%cl
jne    1217 <main+0xd7>
lea    0xe7f(%rip),%rbx
jmp    1200 <main+0xc0>
lea    0xe5d(%rip),%rbx
movsbl %al,%esi
lea    0xc(%rsp),%rdi
call   1060 <media@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Insira a nota %d: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [68 x i8] c"Insira 'P' se deseja media ponderada ou 'A' para media aritmetica: \00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [25 x i8] c"A media ponderada: %.2f\0A\00"
@.str.5 = [26 x i8] c"A media aritmetica: %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x float]
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 %12
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %13)
br label %15
15: ; preds = %8
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %5
18: ; preds = %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stdin
%21 = call i32 @setbuf(i32 %20, i32* null)
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 112
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i8, i8* %4
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 80
br i1 %29, label %30, label %35
30: ; preds = %26, %18
%31 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 0
%32 = load i8, i8* %4
%33 = call double @media(float* %31, i8 signext %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %33)
br label %49
35: ; preds = %26
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 65
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i8, i8* %4
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 97
br i1 %42, label %43, label %48
43: ; preds = %39, %35
%44 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 0
%45 = load i8, i8* %4
%46 = call double @media(float* %44, i8 signext %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), double %46)
br label %48
48: ; preds = %43, %39
br label %49
49: ; preds = %48, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Insira a nota %d: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [68 x i8] c"Insira 'P' se deseja media ponderada ou 'A' para media aritmetica: \00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [25 x i8] c"A media ponderada: %.2f\0A\00"
@.str.5 = [26 x i8] c"A media aritmetica: %.2f\0A\00"
define i32 @main() {
%1 = alloca [3 x float]
%2 = alloca i8
%3 = bitcast [3 x float]* %1 to i8*
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 1
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 2
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @setbuf(i32 %14, i32* null)
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%17 = load i8, i8* %2
%18 = and i8 %17, -33
switch i8 %18, label %24 [
i8 80, label %20
i8 65, label %19
]
19: ; preds = %0
br label %20
20: ; preds = %0, %19
%21 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), %19 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), %0 ]
%22 = call double @media(float* %5, i8 signext %17)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %21, double %22)
br label %24
24: ; preds = %20, %0
ret i32 0
}