#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*/ fixnegzero(char *);
int hputc(char *, char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, double const);
scalar_t__ strlen(char *);
int hputnr8(char *hstring, const char *keyword, const const int ndec,
            const const double dval) {
  char value[30];
  char format[8];
  int i, lval;
  if (ndec < 0) {
    sprintf(format, "%%.%dg", -ndec);
    sprintf(value, format, dval);
    lval = (int)strlen(value);
    for (i = 0; i < lval; i++)
      if (value[i] == 'e') {
        value[i] = 'E';
      }
  } else {
    sprintf(format, "%%.%df", ndec);
    sprintf(value, format, dval);
  }
  fixnegzero(value);
  return (hputc(hstring, keyword, value));
}


x86 assembly (clang, -O0):
<hputnr8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11df <hputnr8+0x9f>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
lea    0xe8a(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    11da <hputnr8+0x9a>
movslq -0x4c(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x65,%eax
jne    11c7 <hputnr8+0x87>
movslq -0x4c(%rbp),%rax
movb   $0x45,-0x40(%rbp,%rax,1)
jmp    11cc <hputnr8+0x8c>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11a0 <hputnr8+0x60>
jmp    1206 <hputnr8+0xc6>
lea    -0x48(%rbp),%rdi
cvtsi2sdl -0x14(%rbp),%xmm0
lea    0xe18(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
call   1060 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <fixnegzero@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <hputc@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hputnr8>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
test   %edx,%edx
movsd  %xmm0,0x28(%rsp)
js     11ac <hputnr8+0x6c>
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
lea    0xebe(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
movq   0x28(%rsp),%xmm0
call   1060 <sprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <fixnegzero@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <hputc@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
neg    %edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
lea    0xe64(%rip),%rsi
lea    0x30(%rsp),%r12
mov    %r12,%rdi
call   1060 <sprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
movq   0x28(%rsp),%xmm0
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1187 <hputnr8+0x47>
mov    %eax,%ecx
cmp    $0x10,%rcx
jae    11f8 <hputnr8+0xb8>
xor    %edx,%edx
jmp    13cd <hputnr8+0x28d>
and    $0xf,%eax
mov    %rcx,%rdx
sub    %rax,%rdx
xor    %esi,%esi
movdqa 0xdf5(%rip),%xmm0
movdqa 0xdfd(%rip),%xmm1
jmp    122d <hputnr8+0xed>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x10,%rsi
cmp    %rsi,%rdx
je     13b6 <hputnr8+0x276>
movq   (%rsp,%rsi,1),%xmm3
movdqa %xmm3,%xmm2
pcmpeqb %xmm0,%xmm2
movd   %xmm2,%edi
test   $0x1,%dil
je     1248 <hputnr8+0x108>
movb   $0x45,(%rsp,%rsi,1)
movdqa %xmm2,%xmm4
pslld  $0x8,%xmm4
movd   %xmm4,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1263 <hputnr8+0x123>
movb   $0x45,0x1(%rsp,%rsi,1)
pshuflw $0x55,%xmm3,%xmm4
pcmpeqb %xmm0,%xmm4
pextrw $0x2,%xmm4,%edi
test   $0x1,%dil
je     127c <hputnr8+0x13c>
movb   $0x45,0x2(%rsp,%rsi,1)
movdqa %xmm2,%xmm4
psllq  $0x18,%xmm4
pextrw $0x3,%xmm4,%edi
test   $0x1,%dil
je     1295 <hputnr8+0x155>
movb   $0x45,0x3(%rsp,%rsi,1)
pshufd $0x55,%xmm3,%xmm3
pcmpeqb %xmm1,%xmm3
pextrw $0x4,%xmm3,%edi
test   $0x1,%dil
je     12ae <hputnr8+0x16e>
movb   $0x45,0x4(%rsp,%rsi,1)
movdqa %xmm2,%xmm3
pslldq $0x5,%xmm3
pextrw $0x5,%xmm3,%edi
test   $0x1,%dil
je     12c7 <hputnr8+0x187>
movb   $0x45,0x5(%rsp,%rsi,1)
pextrw $0x3,%xmm2,%edi
test   $0x1,%dil
je     12d7 <hputnr8+0x197>
movb   $0x45,0x6(%rsp,%rsi,1)
pslldq $0x7,%xmm2
pextrw $0x7,%xmm2,%edi
test   $0x1,%dil
je     12ec <hputnr8+0x1ac>
movb   $0x45,0x7(%rsp,%rsi,1)
movq   0x8(%rsp,%rsi,1),%xmm3
movdqa %xmm3,%xmm2
pcmpeqb %xmm0,%xmm2
movd   %xmm2,%edi
test   $0x1,%dil
je     1309 <hputnr8+0x1c9>
movb   $0x45,0x8(%rsp,%rsi,1)
movdqa %xmm2,%xmm4
pslld  $0x8,%xmm4
movd   %xmm4,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1324 <hputnr8+0x1e4>
movb   $0x45,0x9(%rsp,%rsi,1)
pshuflw $0x55,%xmm3,%xmm4
pcmpeqb %xmm0,%xmm4
pextrw $0x2,%xmm4,%edi
test   $0x1,%dil
je     133d <hputnr8+0x1fd>
movb   $0x45,0xa(%rsp,%rsi,1)
movdqa %xmm2,%xmm4
psllq  $0x18,%xmm4
pextrw $0x3,%xmm4,%edi
test   $0x1,%dil
je     1356 <hputnr8+0x216>
movb   $0x45,0xb(%rsp,%rsi,1)
pshufd $0x55,%xmm3,%xmm3
pcmpeqb %xmm1,%xmm3
pextrw $0x4,%xmm3,%edi
test   $0x1,%dil
je     136f <hputnr8+0x22f>
movb   $0x45,0xc(%rsp,%rsi,1)
movdqa %xmm2,%xmm3
pslldq $0x5,%xmm3
pextrw $0x5,%xmm3,%edi
test   $0x1,%dil
je     1388 <hputnr8+0x248>
movb   $0x45,0xd(%rsp,%rsi,1)
pextrw $0x3,%xmm2,%edi
test   $0x1,%dil
je     1398 <hputnr8+0x258>
movb   $0x45,0xe(%rsp,%rsi,1)
pslldq $0x7,%xmm2
pextrw $0x7,%xmm2,%edi
test   $0x1,%dil
je     1220 <hputnr8+0xe0>
movb   $0x45,0xf(%rsp,%rsi,1)
jmp    1220 <hputnr8+0xe0>
test   %rax,%rax
jne    13cd <hputnr8+0x28d>
jmp    1187 <hputnr8+0x47>
add    $0x1,%rdx
cmp    %rdx,%rcx
je     1187 <hputnr8+0x47>
cmpb   $0x65,(%rsp,%rdx,1)
jne    13c0 <hputnr8+0x280>
movb   $0x45,(%rsp,%rdx,1)
jmp    13c0 <hputnr8+0x280>

LLVM IR (-O0):
@.str = [7 x i8] c"%%.%dg\00"
@.str.1 = [7 x i8] c"%%.%df\00"
define i32 @hputnr8(i8* %0, i8* %1, i32 %2, double %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca [30 x i8]
%10 = alloca [8 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store double %3, double* %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %48
15: ; preds = %4
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%17 = load i32, i32* %7
%18 = sub nsw i32 0, %17
%19 = sitofp i32 %18 to double
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %19)
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%23 = load double, double* %8
%24 = call i32 @sprintf(i8* %21, i8* %22, double %23)
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%26 = call i64 @strlen(i8* %25)
%27 = trunc i64 %26 to i32
store i32 %27, i32* %12
store i32 0, i32* %11
br label %28
28: ; preds = %44, %15
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 101
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 %41
store i8 69, i8* %42
br label %43
43: ; preds = %39, %32
br label %44
44: ; preds = %43
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %28
47: ; preds = %28
br label %57
48: ; preds = %4
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%50 = load i32, i32* %7
%51 = sitofp i32 %50 to double
%52 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %51)
%53 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%55 = load double, double* %8
%56 = call i32 @sprintf(i8* %53, i8* %54, double %55)
br label %57
57: ; preds = %48, %47
%58 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%59 = call i32 @fixnegzero(i8* %58)
%60 = load i8*, i8** %5
%61 = load i8*, i8** %6
%62 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%63 = call i32 @hputc(i8* %60, i8* %61, i8* %62)
ret i32 %63
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%.%dg\00"
@.str.1 = [7 x i8] c"%%.%df\00"
define i32 @hputnr8(i8* %0, i8* %1, i32 %2, double %3) {
%5 = alloca [30 x i8]
%6 = alloca [8 x i8]
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%9 = icmp slt i32 %2, 0
br i1 %9, label %10, label %128
10: ; preds = %4
%11 = sub nsw i32 0, %2
%12 = sitofp i32 %11 to double
%13 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %12)
%14 = call i32 @sprintf(i8* %7, i8* %8, double %3)
%15 = call i64 @strlen(i8* %7)
%16 = trunc i64 %15 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %132
18: ; preds = %10
%19 = and i64 %15, 4294967295
%20 = icmp ult i64 %19, 16
br i1 %20, label %117, label %21
21: ; preds = %18
%22 = and i64 %15, 15
%23 = sub nsw i64 %19, %22
br label %24
24: ; preds = %112, %21
%25 = phi i64 [ 0, %21 ], [ %113, %112 ]
%26 = or i64 %25, 8
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %25
%28 = bitcast i8* %27 to <8 x i8>*
%29 = load <8 x i8>, <8 x i8>* %28
%30 = getelementptr inbounds i8, i8* %27, i64 8
%31 = bitcast i8* %30 to <8 x i8>*
%32 = load <8 x i8>, <8 x i8>* %31
%33 = icmp eq <8 x i8> %29, <i8 101, i8 101, i8 101, i8 101, i8 101, i8 101, i8 101, i8 101>
%34 = icmp eq <8 x i8> %32, <i8 101, i8 101, i8 101, i8 101, i8 101, i8 101, i8 101, i8 101>
%35 = extractelement <8 x i1> %33, i64 0
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %25
store i8 69, i8* %37
br label %38
38: ; preds = %36, %24
%39 = extractelement <8 x i1> %33, i64 1
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = or i64 %25, 1
%42 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %41
store i8 69, i8* %42
br label %43
43: ; preds = %40, %38
%44 = extractelement <8 x i1> %33, i64 2
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = or i64 %25, 2
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %46
store i8 69, i8* %47
br label %48
48: ; preds = %45, %43
%49 = extractelement <8 x i1> %33, i64 3
br i1 %49, label %50, label %53
50: ; preds = %48
%51 = or i64 %25, 3
%52 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %51
store i8 69, i8* %52
br label %53
53: ; preds = %50, %48
%54 = extractelement <8 x i1> %33, i64 4
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = or i64 %25, 4
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %56
store i8 69, i8* %57
br label %58
58: ; preds = %55, %53
%59 = extractelement <8 x i1> %33, i64 5
br i1 %59, label %60, label %63
60: ; preds = %58
%61 = or i64 %25, 5
%62 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %61
store i8 69, i8* %62
br label %63
63: ; preds = %60, %58
%64 = extractelement <8 x i1> %33, i64 6
br i1 %64, label %65, label %68
65: ; preds = %63
%66 = or i64 %25, 6
%67 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %66
store i8 69, i8* %67
br label %68
68: ; preds = %65, %63
%69 = extractelement <8 x i1> %33, i64 7
br i1 %69, label %70, label %73
70: ; preds = %68
%71 = or i64 %25, 7
%72 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %71
store i8 69, i8* %72
br label %73
73: ; preds = %70, %68
%74 = extractelement <8 x i1> %34, i64 0
br i1 %74, label %75, label %77
75: ; preds = %73
%76 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %26
store i8 69, i8* %76
br label %77
77: ; preds = %75, %73
%78 = extractelement <8 x i1> %34, i64 1
br i1 %78, label %79, label %82
79: ; preds = %77
%80 = or i64 %25, 9
%81 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %80
store i8 69, i8* %81
br label %82
82: ; preds = %79, %77
%83 = extractelement <8 x i1> %34, i64 2
br i1 %83, label %84, label %87
84: ; preds = %82
%85 = or i64 %25, 10
%86 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %85
store i8 69, i8* %86
br label %87
87: ; preds = %84, %82
%88 = extractelement <8 x i1> %34, i64 3
br i1 %88, label %89, label %92
89: ; preds = %87
%90 = or i64 %25, 11
%91 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %90
store i8 69, i8* %91
br label %92
92: ; preds = %89, %87
%93 = extractelement <8 x i1> %34, i64 4
br i1 %93, label %94, label %97
94: ; preds = %92
%95 = or i64 %25, 12
%96 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %95
store i8 69, i8* %96
br label %97
97: ; preds = %94, %92
%98 = extractelement <8 x i1> %34, i64 5
br i1 %98, label %99, label %102
99: ; preds = %97
%100 = or i64 %25, 13
%101 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %100
store i8 69, i8* %101
br label %102
102: ; preds = %99, %97
%103 = extractelement <8 x i1> %34, i64 6
br i1 %103, label %104, label %107
104: ; preds = %102
%105 = or i64 %25, 14
%106 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %105
store i8 69, i8* %106
br label %107
107: ; preds = %104, %102
%108 = extractelement <8 x i1> %34, i64 7
br i1 %108, label %109, label %112
109: ; preds = %107
%110 = or i64 %25, 15
%111 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %110
store i8 69, i8* %111
br label %112
112: ; preds = %109, %107
%113 = add nuw i64 %25, 16
%114 = icmp eq i64 %113, %23
br i1 %114, label %115, label %24
115: ; preds = %112
%116 = icmp eq i64 %22, 0
br i1 %116, label %132, label %117
117: ; preds = %18, %115
%118 = phi i64 [ 0, %18 ], [ %23, %115 ]
br label %119
119: ; preds = %117, %125
%120 = phi i64 [ %126, %125 ], [ %118, %117 ]
%121 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %120
%122 = load i8, i8* %121
%123 = icmp eq i8 %122, 101
br i1 %123, label %124, label %125
124: ; preds = %119
store i8 69, i8* %121
br label %125
125: ; preds = %119, %124
%126 = add nuw nsw i64 %120, 1
%127 = icmp eq i64 %126, %19
br i1 %127, label %132, label %119
128: ; preds = %4
%129 = sitofp i32 %2 to double
%130 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %129)
%131 = call i32 @sprintf(i8* %7, i8* %8, double %3)
br label %132
132: ; preds = %125, %115, %10, %128
%133 = call i32 @fixnegzero(i8* %7)
%134 = call i32 @hputc(i8* %0, i8* %1, i8* %7)
ret i32 %134
}