#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 */
char *opt_find(char const *, char const *);
double strtod(char const *, char **);
int opt_get_double(double *d, const char *group, const char *option) {
  double dval;
  const char *val;
  char *endptr = NULL;
  val = opt_find(group, option);
  if (!val)
    return (0);
  endptr = NULL;
  dval = strtod(val, &endptr);
  if (endptr == val)
    return (2);
  if (d)
    *d = dval;
  return (0);
}


x86 assembly (clang, -O0):
<opt_get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <opt_find@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1164 <opt_get_double+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <opt_get_double+0x97>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1198 <opt_get_double+0x78>
movl   $0x2,-0x4(%rbp)
jmp    11b7 <opt_get_double+0x97>
cmpq   $0x0,-0x10(%rbp)
je     11b0 <opt_get_double+0x90>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_get_double>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <opt_find@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     116e <opt_get_double+0x4e>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <strtod@plt>
cmp    %rbx,0x8(%rsp)
je     1169 <opt_get_double+0x49>
test   %r14,%r14
je     116e <opt_get_double+0x4e>
movsd  %xmm0,(%r14)
jmp    116e <opt_get_double+0x4e>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @opt_get_double(double* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca double
%9 = alloca i8*
%10 = alloca i8*
store double* %0, double** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %10
%11 = load i8*, i8** %6
%12 = load i8*, i8** %7
%13 = call i8* @opt_find(i8* %11, i8* %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %3
store i32 0, i32* %4
br label %31
17: ; preds = %3
store i8* null, i8** %10
%18 = load i8*, i8** %9
%19 = call double @strtod(i8* %18, i8** %10)
store double %19, double* %8
%20 = load i8*, i8** %10
%21 = load i8*, i8** %9
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 2, i32* %4
br label %31
24: ; preds = %17
%25 = load double*, double** %5
%26 = icmp ne double* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load double, double* %8
%29 = load double*, double** %5
store double %28, double* %29
br label %30
30: ; preds = %27, %24
store i32 0, i32* %4
br label %31
31: ; preds = %30, %23, %16
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @opt_get_double(double* writeonly %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @opt_find(i8* %1, i8* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %3
store i8* null, i8** %4
%9 = call double @strtod(i8* %6, i8** %4)
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, %6
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = icmp eq double* %0, null
br i1 %13, label %15, label %14
14: ; preds = %12
store double %9, double* %0
br label %15
15: ; preds = %12, %14, %8, %3
%16 = phi i32 [ 0, %3 ], [ 2, %8 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %16
}