#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*/ fprintf(int /*<<< orphan*/, char *, ...);
char *grisu3_parse_double(char const *, int, double *);
int /*<<< orphan*/ grisu3_print_double(double, char *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
void example() {
  double v;
  const char *buf = "1234.34e-4";
  const char *x, *end;
  char result_buf[50];
  int len;
  fprintf(stderr, "grisu3_parse_double example:\n  parsing '%s' as double\n",
          buf);
  len = strlen(buf);
  end = buf + len;
  x = grisu3_parse_double(buf, len, &v);
  if (x == 0) {
    fprintf(stderr, "syntax or range error\n");
  } else if (x == buf) {
    fprintf(stderr, "parse double failed\n");
  } else if (x != end) {
    fprintf(stderr, "parse double did not read everything\n");
  } else {
    fprintf(stderr, "got: %.17g\n", v);
  }
  fprintf(stderr, "grisu3_print_double example:\n  printing %g\n", v);
  grisu3_print_double(v, result_buf);
  fprintf(stderr, "got: %s\n", result_buf);
}


x86 assembly (clang, -O0):
<example>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x64(%rbp),%esi
lea    -0x8(%rbp),%rdx
call   1050 <grisu3_parse_double@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <example+0x84>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    123e <example+0xfe>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11ee <example+0xae>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1239 <example+0xf9>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1218 <example+0xd8>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1234 <example+0xf4>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
lea    0xe67(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    1239 <example+0xf9>
jmp    123e <example+0xfe>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
movsd  -0x8(%rbp),%xmm0
lea    0xe4d(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movsd  -0x8(%rbp),%xmm0
lea    -0x60(%rbp),%rdi
call   1060 <grisu3_print_double@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0x2e91(%rip),%r14
mov    (%r14),%edi
lea    0xeb2(%rip),%rsi
lea    0xea0(%rip),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <grisu3_parse_double@plt>
test   %rax,%rax
je     11a4 <example+0x64>
cmp    %rbx,%rax
je     11b0 <example+0x70>
movslq %ebp,%rcx
add    %rcx,%rbx
mov    (%r14),%edi
cmp    %rbx,%rax
je     1208 <example+0xc8>
lea    0xecc(%rip),%rsi
jmp    11ba <example+0x7a>
mov    (%r14),%edi
lea    0xe94(%rip),%rsi
jmp    11ba <example+0x7a>
mov    (%r14),%edi
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
movsd  0x8(%rsp),%xmm0
lea    0xecf(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <grisu3_print_double@plt>
mov    (%r14),%edi
lea    0xed7(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movsd  0x8(%rsp),%xmm0
lea    0xe7f(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11c1 <example+0x81>

LLVM IR (-O0):
@.str = [11 x i8] c"1234.34e-4\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"grisu3_parse_double example:\0A parsing '%s' as double\0A\00"
@.str.2 = [23 x i8] c"syntax or range error\0A\00"
@.str.3 = [21 x i8] c"parse double failed\0A\00"
@.str.4 = [38 x i8] c"parse double did not read everything\0A\00"
@.str.5 = [12 x i8] c"got: %.17g\0A\00"
@.str.6 = [44 x i8] c"grisu3_print_double example:\0A printing %g\0A\00"
@.str.7 = [9 x i8] c"got: %s\0A\00"
define void @example() {
%1 = alloca double
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [50 x i8]
%6 = alloca i32
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %2
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %2
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8* %15, i8** %4
%16 = load i8*, i8** %2
%17 = load i32, i32* %6
%18 = call i8* @grisu3_parse_double(i8* %16, i32 %17, double* %1)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %44
24: ; preds = %0
%25 = load i8*, i8** %3
%26 = load i8*, i8** %2
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %43
31: ; preds = %24
%32 = load i8*, i8** %3
%33 = load i8*, i8** %4
%34 = icmp ne i8* %32, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %42
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load double, double* %1
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %40)
br label %42
42: ; preds = %38, %35
br label %43
43: ; preds = %42, %28
br label %44
44: ; preds = %43, %21
%45 = load i32, i32* @stderr
%46 = load double, double* %1
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), double %46)
%48 = load double, double* %1
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%50 = call i32 @grisu3_print_double(double %48, i8* %49)
%51 = load i32, i32* @stderr
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %52)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"1234.34e-4\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"grisu3_parse_double example:\0A parsing '%s' as double\0A\00"
@.str.2 = [23 x i8] c"syntax or range error\0A\00"
@.str.3 = [21 x i8] c"parse double failed\0A\00"
@.str.4 = [38 x i8] c"parse double did not read everything\0A\00"
@.str.5 = [12 x i8] c"got: %.17g\0A\00"
@.str.6 = [44 x i8] c"grisu3_print_double example:\0A printing %g\0A\00"
@.str.7 = [9 x i8] c"got: %s\0A\00"
define void @example() {
%1 = alloca double
%2 = alloca [50 x i8]
%3 = bitcast double* %1 to i8*
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %8
%10 = call i8* @grisu3_parse_double(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7, double* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %28
15: ; preds = %0
%16 = icmp eq i8* %10, getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0)
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %28
20: ; preds = %15
%21 = icmp eq i8* %10, %9
%22 = load i32, i32* @stderr
br i1 %21, label %25, label %23
23: ; preds = %20
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %28
25: ; preds = %20
%26 = load double, double* %1
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %26)
br label %28
28: ; preds = %17, %25, %23, %12
%29 = load i32, i32* @stderr
%30 = load double, double* %1
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), double %30)
%32 = load double, double* %1
%33 = call i32 @grisu3_print_double(double %32, i8* %4)
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %4)
ret void
}