#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*/ cube(float);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, float *);
int main(void) {
  float f;
  printf("pls input a float num: ");
  while (scanf("%f", &f) != 1 || getchar() != '\n') {
    while (getchar() != '\n')
      ;
    printf("input error!\n");
    printf("pls input a float num: ");
  }
  printf("cube of %f is %lf\n", f, cube(f));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x9(%rbp)
jne    1190 <main+0x50>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11a0 <main+0x60>
jmp    11de <main+0x9e>
jmp    11a5 <main+0x65>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11bd <main+0x7d>
jmp    11a5 <main+0x65>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115d <main+0x1d>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
call   1060 <cube@plt>
movsd  -0x18(%rbp),%xmm0
mov    %eax,%esi
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xeaf(%rip),%r12
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x50>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11bf <main+0x6f>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <main+0x50>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <main+0x30>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1070 <cube@plt>
lea    0xe40(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"pls input a float num: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [14 x i8] c"input error!\0A\00"
@.str.3 = [19 x i8] c"cube of %f is %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %19, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%6 = icmp ne i32 %5, 1
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = call signext i8 (...) @getchar()
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br label %11
11: ; preds = %7, %4
%12 = phi i1 [ true, %4 ], [ %10, %7 ]
br i1 %12, label %13, label %22
13: ; preds = %11
br label %14
14: ; preds = %18, %13
%15 = call signext i8 (...) @getchar()
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %4
22: ; preds = %11
%23 = load float, float* %2
%24 = fpext float %23 to double
%25 = load float, float* %2
%26 = call i32 @cube(float %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %24, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"pls input a float num: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [19 x i8] c"cube of %f is %lf\0A\00"
@str = [13 x i8] c"input error!\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %14, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %17, label %10
10: ; preds = %4, %7
br label %11
11: ; preds = %10, %11
%12 = call signext i8 (...) @getchar()
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %4
17: ; preds = %7
%18 = load float, float* %1
%19 = fpext float %18 to double
%20 = call i32 @cube(float %18)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %19, i32 %20)
ret i32 0
}