#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
float strtod(char *, char **);
int main() {
  char buffer[4];
  float gas;
  char *p;
  printf("The price of gas: ");
  fgets(buffer, 4, stdin);
  gas = strtod(buffer, &p);
  if (p == buffer)
    puts("Invalid input");
  else
    printf("Wow! %.2f for gas?\n", gas);
  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   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fgets@plt>
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <strtod@plt>
movss  %xmm0,-0xc(%rbp)
mov    -0x18(%rbp),%rax
lea    -0x8(%rbp),%rcx
cmp    %rcx,%rax
jne    11a8 <main+0x68>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
jmp    11bf <main+0x7f>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <fgets@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <strtod@plt>
cmp    %rbx,(%rsp)
je     1193 <main+0x53>
cvtss2sd %xmm0,%xmm0
lea    0xe97(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    119f <main+0x5f>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"The price of gas: \00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid input\00"
@.str.2 = [20 x i8] c"Wow! %.2f for gas?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca float
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 4, i32 %7)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%10 = call float @strtod(i8* %9, i8** %4)
store float %10, float* %3
%11 = load i8*, i8** %4
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %0
%17 = load float, float* %3
%18 = fpext float %17 to double
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %20
20: ; preds = %16, %14
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"The price of gas: \00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid input\00"
@.str.2 = [20 x i8] c"Wow! %.2f for gas?\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 4, i32 %6)
%8 = call float @strtod(i8* %3, i8** %2)
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %3
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
13: ; preds = %0
%14 = fpext float %8 to double
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %16
16: ; preds = %13, %11
ret i32 0
}