void dasm_reginterval(char *dst, unsigned i, unsigned n, int *first) {
  const char *reg;
  char tmp[32];
  if (i < 8) {
    reg = "D";
  } else {
    reg = "A";
    i -= 8;
  }
  if (*first == 0) {
    strcat(dst, "/");
  }
  if (n > 2) {
    sprintf(tmp, "%s%u-%s%u", reg, i, reg, i + n - 1);
  } else if (n == 2) {
    sprintf(tmp, "%s%u/%s%u", reg, i, reg, i + 1);
  } else {
    sprintf(tmp, "%s%u", reg, i);
  }
  strcat(dst, tmp);
  *first = 0;
}


x86 assembly (clang, -O0):
<dasm_reginterval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x8,-0xc(%rbp)
jae    1150 <dasm_reginterval+0x30>
lea    0xeb9(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1164 <dasm_reginterval+0x44>
lea    0xeab(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1181 <dasm_reginterval+0x61>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcat@plt>
cmpl   $0x2,-0x10(%rbp)
jbe    11b9 <dasm_reginterval+0x99>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0xc(%rbp),%r9d
add    -0x10(%rbp),%r9d
sub    $0x1,%r9d
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    120b <dasm_reginterval+0xeb>
cmpl   $0x2,-0x10(%rbp)
jne    11ed <dasm_reginterval+0xcd>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0xc(%rbp),%r9d
add    $0x1,%r9d
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1206 <dasm_reginterval+0xe6>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    120b <dasm_reginterval+0xeb>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <strcat@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dasm_reginterval>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r15
mov    %edx,%r13d
mov    %rdi,%r14
mov    %esi,%ebx
sub    $0x8,%ebx
cmovb  %esi,%ebx
lea    0xeab(%rip),%rax
lea    0xea6(%rip),%r12
cmovb  %rax,%r12
cmpl   $0x0,(%rcx)
je     117c <dasm_reginterval+0x4c>
cmp    $0x3,%r13d
jb     1191 <dasm_reginterval+0x61>
lea    (%rbx,%r13,1),%r9d
add    $0xffffffff,%r9d
lea    0xe8a(%rip),%rsi
jmp    11a2 <dasm_reginterval+0x72>
mov    %r14,%rdi
call   1030 <strlen@plt>
movw   $0x2f,(%r14,%rax,1)
cmp    $0x3,%r13d
jae    116b <dasm_reginterval+0x3b>
cmp    $0x2,%r13d
jne    11b6 <dasm_reginterval+0x86>
lea    0x1(%rbx),%r9d
lea    0xe6c(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %ebx,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11cc <dasm_reginterval+0x9c>
lea    0xe4c(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
movl   $0x0,(%r15)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"D\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [10 x i8] c"%s%u-%s%u\00"
@.str.4 = [10 x i8] c"%s%u/%s%u\00"
@.str.5 = [5 x i8] c"%s%u\00"
define void @dasm_reginterval(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca [32 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%11 = load i32, i32* %6
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %14
13: ; preds = %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9
br label %17
14: ; preds = %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9
%15 = load i32, i32* %6
%16 = sub i32 %15, 8
store i32 %16, i32* %6
br label %17
17: ; preds = %14, %13
%18 = load i32*, i32** %8
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i8* @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %7
%26 = icmp ugt i32 %25, 2
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%29 = load i8*, i8** %9
%30 = load i32, i32* %6
%31 = load i8*, i8** %9
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = add i32 %32, %33
%35 = sub i32 %34, 1
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %30, i8* %31, i32 %35)
br label %54
37: ; preds = %24
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%42 = load i8*, i8** %9
%43 = load i32, i32* %6
%44 = load i8*, i8** %9
%45 = load i32, i32* %6
%46 = add i32 %45, 1
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %43, i8* %44, i32 %46)
br label %53
48: ; preds = %37
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%50 = load i8*, i8** %9
%51 = load i32, i32* %6
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %50, i32 %51)
br label %53
53: ; preds = %48, %40
br label %54
54: ; preds = %53, %27
%55 = load i8*, i8** %5
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%57 = call i8* @strcat(i8* %55, i8* %56)
%58 = load i32*, i32** %8
store i32 0, i32* %58
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"D\00"
@.str.1 = [2 x i8] c"A\00"
@.str.3 = [10 x i8] c"%s%u-%s%u\00"
@.str.4 = [10 x i8] c"%s%u/%s%u\00"
@.str.5 = [5 x i8] c"%s%u\00"
define void @dasm_reginterval(i8* %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = icmp ult i32 %1, 8
%8 = add i32 %1, -8
%9 = select i1 %7, i32 %1, i32 %8
%10 = select i1 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%15 = getelementptr i8, i8* %0, i64 %14
%16 = bitcast i8* %15 to i16*
store i16 47, i16* %16
br label %17
17: ; preds = %13, %4
%18 = icmp ugt i32 %2, 2
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = add i32 %2, -1
%21 = add i32 %20, %9
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %9, i8* %10, i32 %21)
br label %30
23: ; preds = %17
%24 = icmp eq i32 %2, 2
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = add nuw i32 %9, 1
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 %9, i8* %10, i32 %26)
br label %30
28: ; preds = %23
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %9)
br label %30
30: ; preds = %25, %28, %19
%31 = call i8* @strcat(i8* dereferenceable(1) %0, i8* %6)
store i32 0, i32* %3
ret void
}