#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(int);
void ex2() {
  print("\n------------------------------\n");
  int num;
  print("Informe um numero: ");
  scanf("%d", &num);
  while (!(num > 0)) {
    print("Entrada invalida, tente novamente.");
    print("Informe um numero: ");
    scanf("%d", &num);
  }
  float resultado = sqrt(num);
  printf("Resultado: %.2f\n", resultado);
  print("\n------------------------------\n");
}


x86 assembly (clang, -O0):
<ex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <print@plt>
lea    0xec6(%rip),%rdi
call   1040 <print@plt>
lea    0xece(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
setg   %al
xor    $0xff,%al
test   $0x1,%al
jne    1186 <ex2+0x46>
jmp    11b3 <ex2+0x73>
lea    0xeab(%rip),%rdi
call   1040 <print@plt>
lea    0xe88(%rip),%rdi
call   1040 <print@plt>
lea    0xe90(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1170 <ex2+0x30>
mov    -0x4(%rbp),%edi
call   1060 <sqrt@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
lea    0xe28(%rip),%rdi
call   1040 <print@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
call   1040 <print@plt>
lea    0xec6(%rip),%rdi
call   1040 <print@plt>
lea    0xece(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jg     11c3 <ex2+0x83>
lea    0xeb8(%rip),%r14
lea    0xe9a(%rip),%r15
lea    0xea7(%rip),%r12
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <print@plt>
mov    %r15,%rdi
call   1040 <print@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11a0 <ex2+0x60>
call   1060 <sqrt@plt>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe25(%rip),%rdi
call   1040 <print@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A------------------------------\0A\00"
@.str.1 = [20 x i8] c"Informe um numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"Entrada invalida, tente novamente.\00"
@.str.4 = [17 x i8] c"Resultado: %.2f\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = alloca float
%3 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
br label %6
6: ; preds = %10, %0
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = call i32 @print(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
br label %6
14: ; preds = %6
%15 = load i32, i32* %1
%16 = call float @sqrt(i32 %15)
store float %16, float* %2
%17 = load float, float* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), float %17)
%19 = 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 = [20 x i8] c"Informe um numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"Entrada invalida, tente novamente.\00"
@.str.4 = [17 x i8] c"Resultado: %.2f\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = tail call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %0, %8
%9 = call i32 @print(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @print(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 1
br i1 %13, label %8, label %14
14: ; preds = %8, %0
%15 = phi i32 [ %6, %0 ], [ %12, %8 ]
%16 = call float @sqrt(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), float %16)
%18 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret void
}