#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 */
double strtod_cr(char *, char **);
double round_near_(int *ferrno, int *flen, char *field) {
  char *endptr;
  double good;
  int k;
  field[*flen - 1] = '\0';
  for (k = 0; k < *flen - 1; k++) {
    if (field[k] == 'D' || field[k] == 'd') {
      field[k] = 'e';
      break;
    }
  }
  *ferrno = 0;
  good = strtod_cr(field, &endptr);
  return good;
}


x86 assembly (clang, -O0):
<round_near_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a1 <round_near_+0x91>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x44,%eax
je     117d <round_near_+0x6d>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x64,%eax
jne    118e <round_near_+0x7e>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x65,(%rax,%rcx,1)
jmp    11a1 <round_near_+0x91>
jmp    1193 <round_near_+0x83>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113f <round_near_+0x2f>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod_cr@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_near_>:
push   %rax
mov    %rdx,%r8
movslq (%rsi),%rax
movb   $0x0,-0x1(%rax,%rdx,1)
mov    (%rsi),%eax
cmp    $0x2,%eax
jl     114d <round_near_+0x3d>
add    $0xffffffff,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%r8,%rcx,1),%edx
or     $0x20,%dl
cmp    $0x64,%dl
je     1148 <round_near_+0x38>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1130 <round_near_+0x20>
jmp    114d <round_near_+0x3d>
movb   $0x65,(%r8,%rcx,1)
movl   $0x0,(%rdi)
mov    %rsp,%rsi
mov    %r8,%rdi
call   1030 <strtod_cr@plt>
pop    %rax
ret

LLVM IR (-O0):
define double @round_near_(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca double
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
store i32 0, i32* %9
br label %16
16: ; preds = %44, %3
%17 = load i32, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = sub nsw i32 %19, 1
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %47
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 68
br i1 %29, label %38, label %30
30: ; preds = %22
%31 = load i8*, i8** %6
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 100
br i1 %37, label %38, label %43
38: ; preds = %30, %22
%39 = load i8*, i8** %6
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 101, i8* %42
br label %47
43: ; preds = %30
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %16
47: ; preds = %38, %16
%48 = load i32*, i32** %4
store i32 0, i32* %48
%49 = load i8*, i8** %6
%50 = call double @strtod_cr(i8* %49, i8** %7)
store double %50, double* %8
%51 = load double, double* %8
ret double %51
}

LLVM IR (-O2):
define double @round_near_(i32* nocapture writeonly %0, i32* nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %9
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %25
12: ; preds = %3
%13 = add nsw i32 %10, -1
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %12, %22
%16 = phi i64 [ 0, %12 ], [ %23, %22 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %22 [
i8 68, label %19
i8 100, label %19
]
19: ; preds = %15, %15
%20 = and i64 %16, 4294967295
%21 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 101, i8* %21
br label %25
22: ; preds = %15
%23 = add nuw nsw i64 %16, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %25, label %15
25: ; preds = %22, %3, %19
store i32 0, i32* %0
%26 = call double @strtod_cr(i8* %2, i8** %4)
ret double %26
}