#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*/ print(char *);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ scanf(char *, int *);
float sqrt(float);
void ex5() {
  print("\n------------------------------\n");
  int a, b, c;
  print("Informe a medida do lado a:");
  scanf("%d", &a);
  while (!(a > 0)) {
    print("Valor invalido, tente novamente:");
    scanf("%d", &a);
  }
  print("Informe a medida do lado b:");
  scanf("%d", &b);
  while (!(b > 0)) {
    print("Valor invalido, tente novamente:");
    scanf("%d", &b);
  }
  print("Informe a medida do lado c:");
  scanf("%d", &c);
  while (!(c > 0)) {
    print("Valor invalido, tente novamente:");
    scanf("%d", &c);
  }
  float s = (a + b + c) / 2.;
  float area = sqrt(s * (s - a) * (s - b) * (s - c));
  printf("A area do triangulo e: %.2f u.a.\n", area);
  print("\n------------------------------\n");
}


x86 assembly (clang, -O0):
<ex5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb9(%rip),%rdi
call   1040 <print@plt>
lea    0xece(%rip),%rdi
call   1040 <print@plt>
lea    0xede(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
setg   %al
xor    $0xff,%al
test   $0x1,%al
jne    1186 <ex5+0x46>
jmp    11a7 <ex5+0x67>
lea    0xebb(%rip),%rdi
call   1040 <print@plt>
lea    0xeac(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1170 <ex5+0x30>
lea    0xebb(%rip),%rdi
call   1040 <print@plt>
lea    0xe8b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
setg   %al
xor    $0xff,%al
test   $0x1,%al
jne    11d9 <ex5+0x99>
jmp    11fa <ex5+0xba>
lea    0xe68(%rip),%rdi
call   1040 <print@plt>
lea    0xe59(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    11c3 <ex5+0x83>
lea    0xe84(%rip),%rdi
call   1040 <print@plt>
lea    0xe38(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
xor    $0xff,%al
test   $0x1,%al
jne    122c <ex5+0xec>
jmp    124d <ex5+0x10d>
lea    0xe15(%rip),%rdi
call   1040 <print@plt>
lea    0xe06(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1216 <ex5+0xd6>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xd9e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
cvtsi2ssl -0x4(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtsi2ssl -0x8(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
cvtsi2ssl -0xc(%rbp),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
lea    0xd3c(%rip),%rdi
call   1040 <print@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex5>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb8(%rip),%rdi
call   1040 <print@plt>
lea    0xecd(%rip),%rdi
call   1040 <print@plt>
lea    0xedd(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jg     11aa <ex5+0x6a>
lea    0xec8(%rip),%r14
lea    0xebe(%rip),%r15
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <print@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1190 <ex5+0x50>
lea    0xeb8(%rip),%rdi
call   1040 <print@plt>
lea    0xe88(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jg     120a <ex5+0xca>
lea    0xe73(%rip),%r14
lea    0xe69(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <print@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11f0 <ex5+0xb0>
lea    0xe74(%rip),%rdi
call   1040 <print@plt>
lea    0xe28(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jg     126b <ex5+0x12b>
lea    0xe12(%rip),%r14
lea    0xe08(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <print@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1250 <ex5+0x110>
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%edx
lea    (%rcx,%rax,1),%esi
add    %edx,%esi
cvtsi2sd %esi,%xmm0
mulsd  0xd7c(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
cvtsi2ss %ecx,%xmm1
movaps %xmm0,%xmm2
cvtsi2ss %edx,%xmm3
subss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
movaps %xmm0,%xmm1
subss  %xmm3,%xmm1
mulss  %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
subss  %xmm2,%xmm0
mulss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     12c3 <ex5+0x183>
sqrtss %xmm0,%xmm0
jmp    12c8 <ex5+0x188>
call   1060 <sqrt@plt>
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
lea    0xd2d(%rip),%rdi
call   1040 <print@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A------------------------------\0A\00"
@.str.1 = [28 x i8] c"Informe a medida do lado a:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [33 x i8] c"Valor invalido, tente novamente:\00"
@.str.4 = [28 x i8] c"Informe a medida do lado b:\00"
@.str.5 = [28 x i8] c"Informe a medida do lado c:\00"
@.str.6 = [34 x i8] c"A area do triangulo e: %.2f u.a.\0A\00"
define void @ex5() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
br label %9
16: ; preds = %9
%17 = call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %19
19: ; preds = %23, %16
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %19
26: ; preds = %19
%27 = call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %29
29: ; preds = %33, %26
%30 = load i32, i32* %3
%31 = icmp sgt i32 %30, 0
%32 = xor i1 %31, true
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %29
36: ; preds = %29
%37 = load i32, i32* %1
%38 = load i32, i32* %2
%39 = add nsw i32 %37, %38
%40 = load i32, i32* %3
%41 = add nsw i32 %39, %40
%42 = sitofp i32 %41 to double
%43 = fdiv double %42, 2.000000e+00
%44 = fptrunc double %43 to float
store float %44, float* %4
%45 = load float, float* %4
%46 = load float, float* %4
%47 = load i32, i32* %1
%48 = sitofp i32 %47 to float
%49 = fsub float %46, %48
%50 = fmul float %45, %49
%51 = load float, float* %4
%52 = load i32, i32* %2
%53 = sitofp i32 %52 to float
%54 = fsub float %51, %53
%55 = fmul float %50, %54
%56 = load float, float* %4
%57 = load i32, i32* %3
%58 = sitofp i32 %57 to float
%59 = fsub float %56, %58
%60 = fmul float %55, %59
%61 = call float @sqrt(float %60)
store float %61, float* %5
%62 = load float, float* %5
%63 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), float %62)
%64 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"\0A------------------------------\0A\00"
@.str.1 = [28 x i8] c"Informe a medida do lado a:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [33 x i8] c"Valor invalido, tente novamente:\00"
@.str.4 = [28 x i8] c"Informe a medida do lado b:\00"
@.str.5 = [28 x i8] c"Informe a medida do lado c:\00"
@.str.6 = [34 x i8] c"A area do triangulo e: %.2f u.a.\0A\00"
define void @ex5() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %0, %12
%13 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, 1
br i1 %16, label %12, label %17
17: ; preds = %12, %0
%18 = call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %17, %22
%23 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 1
br i1 %26, label %22, label %27
27: ; preds = %22, %17
%28 = call i32 @print(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %27, %32
%33 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 1
br i1 %36, label %32, label %37
37: ; preds = %32, %27
%38 = phi i32 [ %30, %27 ], [ %35, %32 ]
%39 = load i32, i32* %1
%40 = load i32, i32* %2
%41 = add i32 %39, %38
%42 = add i32 %41, %40
%43 = sitofp i32 %42 to double
%44 = fmul double %43, 5.000000e-01
%45 = fptrunc double %44 to float
%46 = sitofp i32 %39 to float
%47 = fsub float %45, %46
%48 = fmul float %47, %45
%49 = sitofp i32 %40 to float
%50 = fsub float %45, %49
%51 = fmul float %50, %48
%52 = sitofp i32 %38 to float
%53 = fsub float %45, %52
%54 = fmul float %53, %51
%55 = call float @sqrt(float %54)
%56 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), float %55)
%57 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret void
}