#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*/ assert(int);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strpbrk(char *, char *);
void _ensure_minimum_exponent_length(char *buffer, size_t buf_size) {
  char *p = strpbrk(buffer, "eE");
  if (p && (*(p + 1) == '-' || *(p + 1) == '+')) {
    char *start = p + 2;
    int exponent_digit_cnt = 0;
    int leading_zero_cnt = 0;
    int in_leading_zeros = 1;
    int significant_digit_cnt;
    p += 2;
    while (*p && isdigit(((*p) & 0xff))) {
      if (in_leading_zeros && *p == '0') {
        ++leading_zero_cnt;
      }
      if (*p != '0') {
        in_leading_zeros = 0;
      }
      ++p;
      ++exponent_digit_cnt;
    }
    significant_digit_cnt = exponent_digit_cnt - leading_zero_cnt;
    if (exponent_digit_cnt == 2) {
    } else if (exponent_digit_cnt > 2) {
      int extra_zeros_cnt;
      if (significant_digit_cnt < 2) {
        significant_digit_cnt = 2;
      }
      extra_zeros_cnt = exponent_digit_cnt - significant_digit_cnt;
      assert(extra_zeros_cnt >= 0);
      memmove(start, start + extra_zeros_cnt, significant_digit_cnt + 1);
    } else {
      int zeros = 2 - exponent_digit_cnt;
      if (start + zeros + exponent_digit_cnt + 1 < buffer + buf_size) {
        memmove(start + zeros, start, exponent_digit_cnt + 1);
        memset(start, '0', zeros);
      }
    }
  }
}


x86 assembly (clang, -O0):
<_ensure_minimum_exponent_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <strpbrk@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     133d <_ensure_minimum_exponent_length+0x1ed>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
je     11a1 <_ensure_minimum_exponent_length+0x51>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2b,%eax
jne    133d <_ensure_minimum_exponent_length+0x1ed>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     1201 <_ensure_minimum_exponent_length+0xb1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
movsbl %al,%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1211 <_ensure_minimum_exponent_length+0xc1>
jmp    1265 <_ensure_minimum_exponent_length+0x115>
cmpl   $0x0,-0x2c(%rbp)
je     1234 <_ensure_minimum_exponent_length+0xe4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1234 <_ensure_minimum_exponent_length+0xe4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     124b <_ensure_minimum_exponent_length+0xfb>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ce <_ensure_minimum_exponent_length+0x7e>
mov    -0x24(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x2,-0x24(%rbp)
jne    127d <_ensure_minimum_exponent_length+0x12d>
jmp    1338 <_ensure_minimum_exponent_length+0x1e8>
cmpl   $0x2,-0x24(%rbp)
jle    12d1 <_ensure_minimum_exponent_length+0x181>
cmpl   $0x2,-0x30(%rbp)
jge    1298 <_ensure_minimum_exponent_length+0x148>
movl   $0x2,-0x30(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
add    $0x1,%edx
call   1070 <memmove@plt>
jmp    1333 <_ensure_minimum_exponent_length+0x1e3>
mov    $0x2,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    132e <_ensure_minimum_exponent_length+0x1de>
mov    -0x20(%rbp),%rdi
movslq -0x38(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
call   1070 <memmove@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%edx
mov    $0x30,%esi
call   1040 <memset@plt>
jmp    1333 <_ensure_minimum_exponent_length+0x1e3>
jmp    1338 <_ensure_minimum_exponent_length+0x1e8>
jmp    133d <_ensure_minimum_exponent_length+0x1ed>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ensure_minimum_exponent_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe95(%rip),%rsi
call   1060 <strpbrk@plt>
test   %rax,%rax
je     1293 <_ensure_minimum_exponent_length+0x143>
mov    %rax,%r12
mov    %rax,%r13
mov    0x1(%r12),%al
cmp    $0x2d,%al
je     1190 <_ensure_minimum_exponent_length+0x40>
cmp    $0x2b,%al
jne    1293 <_ensure_minimum_exponent_length+0x143>
add    $0x2,%r12
mov    0x2(%r13),%al
test   %al,%al
je     1248 <_ensure_minimum_exponent_length+0xf8>
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
xor    %r14d,%r14d
mov    $0x1,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11f5 <_ensure_minimum_exponent_length+0xa5>
test   %r15d,%r15d
setne  %cl
movzbl 0x3(%r13,%rbx,1),%eax
cmpb   $0x30,0x2(%r13,%rbx,1)
sete   %dl
cmovne %r14d,%r15d
and    %cl,%dl
movzbl %dl,%ecx
add    %ecx,%ebp
add    $0x1,%rbx
test   %al,%al
jne    11c0 <_ensure_minimum_exponent_length+0x70>
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%r15
cmp    $0x2,%ebx
je     1293 <_ensure_minimum_exponent_length+0x143>
jbe    124a <_ensure_minimum_exponent_length+0xfa>
mov    %ebx,%eax
sub    %ebp,%eax
cmp    $0x3,%eax
mov    $0x2,%ebp
cmovge %eax,%ebp
sub    %ebp,%ebx
mov    %ebx,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
movslq %ebx,%rsi
add    %r12,%rsi
add    $0x1,%ebp
mov    %r12,%rdi
mov    %ebp,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <memmove@plt>
xor    %ebx,%ebx
mov    $0x2,%r13d
sub    %ebx,%r13d
lea    (%r12,%r13,1),%rdi
mov    %ebx,%eax
add    %rdi,%rax
add    $0x1,%rax
add    %r14,%r15
cmp    %r15,%rax
jae    1293 <_ensure_minimum_exponent_length+0x143>
add    $0x1,%ebx
mov    %r12,%rsi
mov    %ebx,%edx
call   1070 <memmove@plt>
mov    %r12,%rdi
mov    $0x30,%esi
mov    %r13d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memset@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"eE\00"
define void @_ensure_minimum_exponent_length(i8* %0, i64 %1) {
%3 = tail call i8* @strpbrk(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %65, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
switch i8 %7, label %65 [
i8 45, label %8
i8 43, label %8
]
8: ; preds = %5, %5
%9 = getelementptr inbounds i8, i8* %3, i64 2
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %51, label %12
12: ; preds = %8, %20
%13 = phi i8 [ %31, %20 ], [ %10, %8 ]
%14 = phi i8* [ %29, %20 ], [ %9, %8 ]
%15 = phi i32 [ %30, %20 ], [ 0, %8 ]
%16 = phi i32 [ %28, %20 ], [ 1, %8 ]
%17 = phi i32 [ %26, %20 ], [ 0, %8 ]
%18 = tail call i64 @isdigit(i8 signext %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %12
%21 = icmp ne i32 %16, 0
%22 = load i8, i8* %14
%23 = icmp eq i8 %22, 48
%24 = select i1 %21, i1 %23, i1 false
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %17, %25
%27 = icmp eq i8 %22, 48
%28 = select i1 %27, i32 %16, i32 0
%29 = getelementptr inbounds i8, i8* %14, i64 1
%30 = add nuw nsw i32 %15, 1
%31 = load i8, i8* %29
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %12
33: ; preds = %12, %20
%34 = phi i32 [ %17, %12 ], [ %26, %20 ]
%35 = phi i32 [ %15, %12 ], [ %30, %20 ]
%36 = sub nsw i32 %35, %34
%37 = icmp eq i32 %35, 2
br i1 %37, label %65, label %38
38: ; preds = %33
%39 = icmp ugt i32 %35, 2
br i1 %39, label %40, label %51
40: ; preds = %38
%41 = icmp sgt i32 %36, 2
%42 = select i1 %41, i32 %36, i32 2
%43 = sub nsw i32 %35, %42
%44 = xor i32 %43, -1
%45 = lshr i32 %44, 31
%46 = tail call i32 @assert(i32 %45)
%47 = sext i32 %43 to i64
%48 = getelementptr inbounds i8, i8* %9, i64 %47
%49 = add nuw nsw i32 %42, 1
%50 = tail call i32 @memmove(i8* %9, i8* %48, i32 %49)
br label %65
51: ; preds = %8, %38
%52 = phi i32 [ %35, %38 ], [ 0, %8 ]
%53 = sub nuw nsw i32 2, %52
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %9, i64 %54
%56 = zext i32 %52 to i64
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = getelementptr inbounds i8, i8* %0, i64 %1
%60 = icmp ult i8* %58, %59
br i1 %60, label %61, label %65
61: ; preds = %51
%62 = add nuw nsw i32 %52, 1
%63 = tail call i32 @memmove(i8* %55, i8* %9, i32 %62)
%64 = tail call i32 @memset(i8* %9, i32 48, i32 %53)
br label %65
65: ; preds = %33, %40, %61, %51, %5, %2
ret void
}