#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 *, ...);
void ex4() {
  int code, type;
  float kwh, total[3];
  while (code != 0) {
    printf("Digite o numero do consumidor: ");
    scanf("%d", &code);
    printf("Digite quantidade de KWh consumidos: ");
    scanf("%f", &kwh);
    printf("Digite o tipo do consumidor: ");
    scanf("%d", &type);
    if (type == 1) {
      total[0] += kwh * .5;
      printf("O custo total para o consumidor %d e %.2f\n", code, kwh * .5);
    }
    if (type == 2) {
      total[1] += kwh * .7;
      printf("O custo total para o consumidor %d e %.2f\n", code, kwh * .7);
    }
    if (type == 3) {
      total[2] += kwh * 1.2;
      printf("O custo total para o consumidor %d e %.2f\n", code, kwh * 1.2);
    }
  }
  printf("O total para os 3 tipos de consumidores e %.2f.\n",
         total[0] + total[1] + total[2]);
  printf("A media do consumido dos tipos 1 e 2 e %.2f.\n",
         (float)(total[0] + total[1]) / 2.);
}


x86 assembly (clang, -O0):
<ex4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,-0x4(%rbp)
je     12a8 <ex4+0x188>
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef9(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11ed <ex4+0xcd>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%esi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2d(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xea4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1248 <ex4+0x128>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xdff(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x4(%rbp),%esi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdda(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xe49(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    12a3 <ex4+0x183>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xdac(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%esi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd87(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xdee(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1128 <ex4+0x8>
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd21(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf03(%rip),%rbx
lea    0xf25(%rip),%r13
lea    0x8(%rsp),%rbp
lea    0xf1c(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xf2e(%rip),%r12
jmp    116b <ex4+0x4b>
cs nopw 0x0(%rax,%rax,1)
cmpl   $0x0,0x4(%rsp)
je     12a1 <ex4+0x181>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
je     11e0 <ex4+0xc0>
cmp    $0x2,%eax
je     1221 <ex4+0x101>
cmp    $0x3,%eax
jne    1160 <ex4+0x40>
jmp    1264 <ex4+0x144>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe04(%rip),%xmm0
addsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x10(%rsp)
mov    0x4(%rsp),%esi
mov    %r12,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jne    11c8 <ex4+0xa8>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xdcc(%rip),%xmm0
addsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%rsp)
mov    0x4(%rsp),%esi
mov    %r12,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
jne    1160 <ex4+0x40>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x14(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xd90(%rip),%xmm0
addsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x14(%rsp)
mov    0x4(%rsp),%esi
mov    %r12,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1160 <ex4+0x40>
movss  (%rsp),%xmm1
addss  0x10(%rsp),%xmm1
movss  %xmm1,(%rsp)
movss  0x14(%rsp),%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xd22(%rip),%xmm0
lea    0xdf9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Digite o numero do consumidor: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Digite quantidade de KWh consumidos: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [30 x i8] c"Digite o tipo do consumidor: \00"
@.str.5 = [43 x i8] c"O custo total para o consumidor %d e %.2f\0A\00"
@.str.6 = [49 x i8] c"O total para os 3 tipos de consumidores e %.2f.\0A\00"
@.str.7 = [46 x i8] c"A media do consumido dos tipos 1 e 2 e %.2f.\0A\00"
define void @ex4() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca [3 x float]
br label %5
5: ; preds = %62, %0
%6 = load i32, i32* %1
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %63
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %8
%18 = load float, float* %3
%19 = fpext float %18 to double
%20 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 0
%21 = load float, float* %20
%22 = fpext float %21 to double
%23 = call double @llvm.fmuladd.f64(double %19, double 5.000000e-01, double %22)
%24 = fptrunc double %23 to float
store float %24, float* %20
%25 = load i32, i32* %1
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = fmul double %27, 5.000000e-01
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %25, double %28)
br label %30
30: ; preds = %17, %8
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 1
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = call double @llvm.fmuladd.f64(double %35, double 0x3FE6666666666666, double %38)
%40 = fptrunc double %39 to float
store float %40, float* %36
%41 = load i32, i32* %1
%42 = load float, float* %3
%43 = fpext float %42 to double
%44 = fmul double %43, 0x3FE6666666666666
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %41, double %44)
br label %46
46: ; preds = %33, %30
%47 = load i32, i32* %2
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %62
49: ; preds = %46
%50 = load float, float* %3
%51 = fpext float %50 to double
%52 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 2
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = call double @llvm.fmuladd.f64(double %51, double 1.200000e+00, double %54)
%56 = fptrunc double %55 to float
store float %56, float* %52
%57 = load i32, i32* %1
%58 = load float, float* %3
%59 = fpext float %58 to double
%60 = fmul double %59, 1.200000e+00
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %57, double %60)
br label %62
62: ; preds = %49, %46
br label %5
63: ; preds = %5
%64 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 0
%65 = load float, float* %64
%66 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 1
%67 = load float, float* %66
%68 = fadd float %65, %67
%69 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 2
%70 = load float, float* %69
%71 = fadd float %68, %70
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), double %72)
%74 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 0
%75 = load float, float* %74
%76 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 1
%77 = load float, float* %76
%78 = fadd float %75, %77
%79 = fpext float %78 to double
%80 = fdiv double %79, 2.000000e+00
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), double %80)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Digite o numero do consumidor: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Digite quantidade de KWh consumidos: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [30 x i8] c"Digite o tipo do consumidor: \00"
@.str.5 = [43 x i8] c"O custo total para o consumidor %d e %.2f\0A\00"
@.str.6 = [49 x i8] c"O total para os 3 tipos de consumidores e %.2f.\0A\00"
@.str.7 = [46 x i8] c"A media do consumido dos tipos 1 e 2 e %.2f.\0A\00"
define void @ex4() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast float* %3 to i8*
br label %7
7: ; preds = %0, %56
%8 = phi float [ %31, %56 ], [ undef, %0 ]
%9 = phi float [ %45, %56 ], [ undef, %0 ]
%10 = phi float [ %57, %56 ], [ undef, %0 ]
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %29
19: ; preds = %7
%20 = load float, float* %3
%21 = fpext float %20 to double
%22 = fpext float %8 to double
%23 = call double @llvm.fmuladd.f64(double %21, double 5.000000e-01, double %22)
%24 = fptrunc double %23 to float
%25 = load i32, i32* %1
%26 = fmul double %21, 5.000000e-01
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %25, double %26)
%28 = load i32, i32* %2
br label %29
29: ; preds = %19, %7
%30 = phi i32 [ %28, %19 ], [ %17, %7 ]
%31 = phi float [ %24, %19 ], [ %8, %7 ]
%32 = icmp eq i32 %30, 2
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = fpext float %9 to double
%37 = call double @llvm.fmuladd.f64(double %35, double 0x3FE6666666666666, double %36)
%38 = fptrunc double %37 to float
%39 = load i32, i32* %1
%40 = fmul double %35, 0x3FE6666666666666
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %39, double %40)
%42 = load i32, i32* %2
br label %43
43: ; preds = %33, %29
%44 = phi i32 [ %42, %33 ], [ %30, %29 ]
%45 = phi float [ %38, %33 ], [ %9, %29 ]
%46 = icmp eq i32 %44, 3
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load float, float* %3
%49 = fpext float %48 to double
%50 = fpext float %10 to double
%51 = call double @llvm.fmuladd.f64(double %49, double 1.200000e+00, double %50)
%52 = fptrunc double %51 to float
%53 = load i32, i32* %1
%54 = fmul double %49, 1.200000e+00
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %53, double %54)
br label %56
56: ; preds = %47, %43
%57 = phi float [ %52, %47 ], [ %10, %43 ]
%58 = load i32, i32* %1
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %7
60: ; preds = %56
%61 = fadd float %45, %31
%62 = fadd float %57, %61
%63 = fpext float %62 to double
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), double %63)
%65 = fpext float %61 to double
%66 = fmul double %65, 5.000000e-01
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), double %66)
ret void
}