#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 */
scalar_t__ BUFSIZ;
int /*<<< orphan*/ _exit(int);
char *realloc(char *, size_t);
int strlen(char *);
scalar_t__ write(int, char *, int);
char *expand_sequence(char *res, size_t *rlen, unsigned int *i, char from,
                      char to) {
  size_t siz = (*rlen);
  while (siz < (strlen(res) + 1 + (unsigned)(to - from))) {
    siz += BUFSIZ;
    if (!(res = realloc(res, siz)))
      do {
        if (write(2, "realloc failed", strlen("realloc failed")) > 0 &&
            write(2, "\n", 1) > 0) {
        };
        _exit(1);
      } while (0);
  }
  while (to >= from)
    res[(*i)++] = from++;
  res[(*i)] = '\0';
  (*rlen) = siz;
  return res;
}


x86 assembly (clang, -O0):
<expand_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0x1,%ecx
movsbl -0x1a(%rbp),%edx
movsbl -0x19(%rbp),%esi
sub    %esi,%edx
add    %edx,%ecx
mov    %ecx,%ecx
cmp    %rcx,%rax
jae    1228 <expand_sequence+0xe8>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1223 <expand_sequence+0xe3>
jmp    11cb <expand_sequence+0x8b>
lea    0xe2e(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe1b(%rip),%rsi
call   1040 <write@plt>
cmp    $0x0,%rax
jle    1219 <expand_sequence+0xd9>
mov    $0x2,%edi
lea    0xe0f(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jle    1219 <expand_sequence+0xd9>
jmp    1219 <expand_sequence+0xd9>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    1168 <expand_sequence+0x28>
jmp    122d <expand_sequence+0xed>
movsbl -0x1a(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jl     1262 <expand_sequence+0x122>
mov    -0x19(%rbp),%dl
mov    %dl,%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    122d <expand_sequence+0xed>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_sequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %rdx,%r12
mov    %rdi,%rbx
mov    %rsi,0x10(%rsp)
mov    (%rsi),%rbp
mov    %r8d,0xc(%rsp)
sub    %ecx,%r15d
add    $0x1,%r15d
mov    0x2e6b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %r15d,%eax
cmp    %rax,%rbp
jae    11e9 <expand_sequence+0xa9>
add    (%r14),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <expand_sequence+0x40>
lea    0xe53(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jle    11df <expand_sequence+0x9f>
lea    0xe3f(%rip),%rsi
mov    $0x2,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    0xc(%rsp),%edx
cmp    %dl,%r13b
jg     1218 <expand_sequence+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%r12)
mov    %r13b,(%rbx,%rax,1)
add    $0x1,%r13b
cmp    %dl,%r13b
jle    1200 <expand_sequence+0xc0>
mov    (%r12),%eax
movb   $0x0,(%rbx,%rax,1)
mov    0x10(%rsp),%rax
mov    %rbp,(%rax)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i64 0
@.str = [15 x i8] c"realloc failed\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @expand_sequence(i8* %0, i64* %1, i32* %2, i8 signext %3, i8 signext %4) {
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i64
store i8* %0, i8** %6
store i64* %1, i64** %7
store i32* %2, i32** %8
store i8 %3, i8* %9
store i8 %4, i8* %10
%12 = load i64*, i64** %7
%13 = load i64, i64* %12
store i64 %13, i64* %11
br label %14
14: ; preds = %47, %5
%15 = load i64, i64* %11
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
%19 = load i8, i8* %10
%20 = sext i8 %19 to i32
%21 = load i8, i8* %9
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %20, %22
%24 = add i32 %18, %23
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %15, %25
br i1 %26, label %27, label %48
27: ; preds = %14
%28 = load i64, i64* @BUFSIZ
%29 = load i64, i64* %11
%30 = add i64 %29, %28
store i64 %30, i64* %11
%31 = load i8*, i8** %6
%32 = load i64, i64* %11
%33 = call i8* @realloc(i8* %31, i64 %32)
store i8* %33, i8** %6
%34 = icmp ne i8* %33, null
br i1 %34, label %47, label %35
35: ; preds = %27
br label %36
36: ; preds = %35
%37 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%38 = call i64 @write(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i64 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%42 = icmp sgt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
br label %44
44: ; preds = %43, %40, %36
%45 = call i32 @_exit(i32 1)
unreachable
46: ; No predecessors!
br label %47
47: ; preds = %46, %27
br label %14
48: ; preds = %14
br label %49
49: ; preds = %55, %48
%50 = load i8, i8* %10
%51 = sext i8 %50 to i32
%52 = load i8, i8* %9
%53 = sext i8 %52 to i32
%54 = icmp sge i32 %51, %53
br i1 %54, label %55, label %64
55: ; preds = %49
%56 = load i8, i8* %9
%57 = add i8 %56, 1
store i8 %57, i8* %9
%58 = load i8*, i8** %6
%59 = load i32*, i32** %8
%60 = load i32, i32* %59
%61 = add i32 %60, 1
store i32 %61, i32* %59
%62 = zext i32 %60 to i64
%63 = getelementptr inbounds i8, i8* %58, i64 %62
store i8 %56, i8* %63
br label %49
64: ; preds = %49
%65 = load i8*, i8** %6
%66 = load i32*, i32** %8
%67 = load i32, i32* %66
%68 = zext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
store i8 0, i8* %69
%70 = load i64, i64* %11
%71 = load i64*, i64** %7
store i64 %70, i64* %71
%72 = load i8*, i8** %6
ret i8* %72
}

LLVM IR (-O2):
@BUFSIZ = global i64 0
@.str = [15 x i8] c"realloc failed\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @expand_sequence(i8* %0, i64* nocapture %1, i32* nocapture %2, i8 signext %3, i8 signext %4) {
%6 = load i64, i64* %1
%7 = sext i8 %4 to i32
%8 = sext i8 %3 to i32
%9 = sub nsw i32 1, %8
%10 = add nsw i32 %9, %7
br label %11
11: ; preds = %20, %5
%12 = phi i8* [ %0, %5 ], [ %23, %20 ]
%13 = phi i64 [ %6, %5 ], [ %22, %20 ]
%14 = tail call i32 @strlen(i8* %12)
%15 = add i32 %10, %14
%16 = zext i32 %15 to i64
%17 = icmp ult i64 %13, %16
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = icmp sgt i8 %3, %4
br i1 %19, label %41, label %33
20: ; preds = %11
%21 = load i64, i64* @BUFSIZ
%22 = add i64 %21, %13
%23 = tail call i8* @realloc(i8* %12, i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %11
25: ; preds = %20
%26 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%27 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %31
31: ; preds = %29, %25
%32 = tail call i32 @_exit(i32 1)
unreachable
33: ; preds = %18, %33
%34 = phi i8 [ %35, %33 ], [ %3, %18 ]
%35 = add i8 %34, 1
%36 = load i32, i32* %2
%37 = add i32 %36, 1
store i32 %37, i32* %2
%38 = zext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %12, i64 %38
store i8 %34, i8* %39
%40 = icmp sgt i8 %35, %4
br i1 %40, label %41, label %33
41: ; preds = %33, %18
%42 = load i32, i32* %2
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %12, i64 %43
store i8 0, i8* %44
store i64 %13, i64* %1
ret i8* %12
}