int hputnr8(hstring, keyword, ndec, dval)
char *hstring;
char *keyword;
int ndec;
double dval;
{
  char value[30];
  char format[8];
  unsigned int i;
  if (ndec < 0) {
    sprintf(format, "%%.%dg", -ndec);
    sprintf(value, format, dval);
    for (i = 0; i < strlen(value); i++)
      if (value[i] == 'e')
        value[i] = 'E';
  } else {
    sprintf(format, "%%.%df", ndec);
    sprintf(value, format, dval);
  }
  return (hputc(hstring, keyword, value));
}


x86 assembly (clang, -O0):
<hputnr8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <hputnr8+0xa5>
lea    -0x48(%rbp),%rdi
xor    %edx,%edx
sub    -0x14(%rbp),%edx
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jae    11d0 <hputnr8+0xa0>
mov    -0x4c(%rbp),%eax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x65,%eax
jne    11bd <hputnr8+0x8d>
mov    -0x4c(%rbp),%eax
movb   $0x45,-0x40(%rbp,%rax,1)
jmp    11c2 <hputnr8+0x92>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1184 <hputnr8+0x54>
jmp    11fe <hputnr8+0xce>
lea    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x0,%al
call   1040 <hputc@plt>
add    $0x60,%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,(%rsp)
js     1192 <hputnr8+0x62>
lea    0xeb6(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <hputc@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
neg    %edx
lea    0xe65(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    0x10(%rsp),%al
test   %al,%al
je     1174 <hputnr8+0x44>
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
cmp    $0x65,%al
jne    11e5 <hputnr8+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x45,0x10(%rsp,%rbx,1)
add    $0x1,%ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %rbx,%rax
jbe    1174 <hputnr8+0x44>
movzbl 0x10(%rsp,%rbx,1),%eax
cmp    $0x65,%al
je     11e0 <hputnr8+0xb0>
jmp    11e5 <hputnr8+0xb5>

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
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store double %3, double* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %4
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* %7
%17 = sub nsw i32 0, %16
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%21 = load double, double* %8
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* %20, double %21)
store i32 0, i32* %11
br label %23
23: ; preds = %41, %14
%24 = load i32, i32* %11
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = icmp ult i64 %25, %27
br i1 %28, label %29, label %44
29: ; preds = %23
%30 = load i32, i32* %11
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 101
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = load i32, i32* %11
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 %38
store i8 69, i8* %39
br label %40
40: ; preds = %36, %29
br label %41
41: ; preds = %40
%42 = load i32, i32* %11
%43 = add i32 %42, 1
store i32 %43, i32* %11
br label %23
44: ; preds = %23
br label %53
45: ; preds = %4
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%47 = load i32, i32* %7
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%51 = load double, double* %8
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* %50, double %51)
br label %53
53: ; preds = %45, %44
%54 = load i8*, i8** %5
%55 = load i8*, i8** %6
%56 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%57 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @hputc to i32 (i8*, i8*, i8*, ...)*)(i8* %54, i8* %55, i8* %56)
ret i32 %57
}

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 %30
10: ; preds = %4
%11 = sub nsw i32 0, %2
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* %8, double %3)
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %10, %27
%17 = phi i8 [ %29, %27 ], [ %14, %10 ]
%18 = phi i64 [ %24, %27 ], [ 0, %10 ]
%19 = icmp eq i8 %17, 101
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %18
store i8 69, i8* %21
br label %22
22: ; preds = %16, %20
%23 = add nuw nsw i64 %18, 1
%24 = and i64 %23, 4294967295
%25 = call i64 @strlen(i8* %7)
%26 = icmp ugt i64 %25, %24
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %24
%29 = load i8, i8* %28
br label %16
30: ; preds = %4
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* %8, double %3)
br label %33
33: ; preds = %22, %10, %30
%34 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @hputc to i32 (i8*, i8*, i8*, ...)*)(i8* %0, i8* %1, i8* %7)
ret i32 %34
}