#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
float strtod(char *, char **);
int main() {
  char buffer[4];
  float gas;
  char *p;
  printf("The price of gas: ");
  fgets(buffer, 4, stdin);
  if (strcmp(buffer, "nan") == 0 || strcmp(buffer, "inf") == 0) {
    puts("Invalid input");
    exit(1);
  }
  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    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fgets@plt>
lea    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11c8 <main+0x68>
lea    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11de <main+0x7e>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@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    1212 <main+0xb2>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
jmp    1229 <main+0xc9>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe07(%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    0xe94(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <fgets@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f7 <main+0x97>
lea    0xe6e(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f7 <main+0x97>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtod@plt>
cmp    %rbx,0x8(%rsp)
je     11e3 <main+0x83>
cvtss2sd %xmm0,%xmm0
lea    0xe4f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11ef <main+0x8f>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"The price of gas: \00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"nan\00"
@.str.2 = [4 x i8] c"inf\00"
@.str.3 = [14 x i8] c"Invalid input\00"
@.str.4 = [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 i64 @strcmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12, %0
%17 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%21 = call float @strtod(i8* %20, i8** %4)
store float %21, float* %3
%22 = load i8*, i8** %4
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%24 = icmp eq i8* %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %31
27: ; preds = %19
%28 = load float, float* %3
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %29)
br label %31
31: ; preds = %27, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"The price of gas: \00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"nan\00"
@.str.2 = [4 x i8] c"inf\00"
@.str.3 = [14 x i8] c"Invalid input\00"
@.str.4 = [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 i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10, %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = call float @strtod(i8* %3, i8** %2)
%18 = load i8*, i8** %2
%19 = icmp eq i8* %18, %3
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %25
22: ; preds = %16
%23 = fpext float %17 to double
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %23)
br label %25
25: ; preds = %22, %20
ret i32 0
}