char *hist_error(s, start, current, errtype)
char *s;
int start, current, errtype;
{
  char *temp;
  const char *emsg;
  int ll, elen;
  ll = current - start;
  switch (errtype) {
  case 0:
    emsg = "event not found";
    elen = 15;
    break;
  case 1:
    emsg = "bad word specifier";
    elen = 18;
    break;
  case 2:
    emsg = "substitution failed";
    elen = 19;
    break;
  case 3:
    emsg = "unrecognized history modifier";
    elen = 29;
    break;
  case 4:
    emsg = "no previous substitution";
    elen = 24;
    break;
  default:
    emsg = "unknown expansion error";
    elen = 23;
    break;
  }
  temp = (char *)xmalloc(ll + elen + 3);
  strncpy(temp, s + start, ll);
  temp[ll] = ':';
  temp[ll + 1] = ' ';
  strcpy(temp + ll + 2, emsg);
  return (temp);
}


x86 assembly (clang, -O0):
<hist_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x4,%rax
ja     11e8 <hist_error+0xb8>
mov    -0x38(%rbp),%rax
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe98(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0xf,-0x30(%rbp)
jmp    11fa <hist_error+0xca>
lea    0xe91(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x12,-0x30(%rbp)
jmp    11fa <hist_error+0xca>
lea    0xe8d(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x13,-0x30(%rbp)
jmp    11fa <hist_error+0xca>
lea    0xe8a(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1d,-0x30(%rbp)
jmp    11fa <hist_error+0xca>
lea    0xe91(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x18,-0x30(%rbp)
jmp    11fa <hist_error+0xca>
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x17,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
add    -0x30(%rbp),%edi
add    $0x3,%edi
mov    $0x0,%al
call   1050 <xmalloc@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
movslq -0x2c(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
add    $0x2,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hist_error>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%r14
sub    %esi,%ebx
cmp    $0x4,%ecx
ja     1164 <hist_error+0x34>
movslq %ecx,%rax
lea    0xf37(%rip),%rcx
movslq (%rcx,%rax,4),%r15
add    %rcx,%r15
lea    0xf3d(%rip),%rcx
mov    (%rcx,%rax,4),%eax
jmp    1170 <hist_error+0x40>
mov    $0x17,%eax
lea    0xefe(%rip),%r15
lea    (%rbx,%rax,1),%edi
add    $0x3,%edi
xor    %eax,%eax
call   1050 <xmalloc@plt>
movslq %eax,%rbp
movslq %r12d,%rax
add    %rax,%r14
movslq %ebx,%rbx
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movw   $0x203a,0x0(%rbp,%rbx,1)
lea    (%rbx,%rbp,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"event not found\00"
@.str.1 = [19 x i8] c"bad word specifier\00"
@.str.2 = [20 x i8] c"substitution failed\00"
@.str.3 = [30 x i8] c"unrecognized history modifier\00"
@.str.4 = [25 x i8] c"no previous substitution\00"
@.str.5 = [24 x i8] c"unknown expansion error\00"
define i8* @hist_error(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 i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = sub nsw i32 %13, %14
store i32 %15, i32* %11
%16 = load i32, i32* %8
switch i32 %16, label %22 [
i32 0, label %17
i32 1, label %18
i32 2, label %19
i32 3, label %20
i32 4, label %21
]
17: ; preds = %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %10
store i32 15, i32* %12
br label %23
18: ; preds = %4
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i32 18, i32* %12
br label %23
19: ; preds = %4
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8** %10
store i32 19, i32* %12
br label %23
20: ; preds = %4
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8** %10
store i32 29, i32* %12
br label %23
21: ; preds = %4
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8** %10
store i32 24, i32* %12
br label %23
22: ; preds = %4
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8** %10
store i32 23, i32* %12
br label %23
23: ; preds = %22, %21, %20, %19, %18, %17
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = add nsw i32 %24, %25
%27 = add nsw i32 %26, 3
%28 = call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %27)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = call i8* @strncpy(i8* %31, i8* %35, i64 %37)
%39 = load i8*, i8** %9
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 58, i8* %42
%43 = load i8*, i8** %9
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 32, i8* %47
%48 = load i8*, i8** %9
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = getelementptr inbounds i8, i8* %51, i64 2
%53 = load i8*, i8** %10
%54 = call i8* @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %9
ret i8* %55
}

LLVM IR (-O2):
@.str = [16 x i8] c"event not found\00"
@.str.1 = [19 x i8] c"bad word specifier\00"
@.str.2 = [20 x i8] c"substitution failed\00"
@.str.3 = [30 x i8] c"unrecognized history modifier\00"
@.str.4 = [25 x i8] c"no previous substitution\00"
@.str.5 = [24 x i8] c"unknown expansion error\00"
@reltable.hist_error = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.hist_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.hist_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.hist_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.hist_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.hist_error to i64)) to i32)]
@switch.table.hist_error.6 = [5 x i32] [i32 15, i32 18, i32 19, i32 29, i32 24]
define i8* @hist_error(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %2, %1
%6 = icmp ult i32 %3, 5
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = sext i32 %3 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.hist_error to i8*), i64 %9)
%11 = sext i32 %3 to i64
%12 = getelementptr inbounds [5 x i32], [5 x i32]* @switch.table.hist_error.6, i64 0, i64 %11
%13 = load i32, i32* %12
br label %14
14: ; preds = %4, %7
%15 = phi i8* [ %10, %7 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), %4 ]
%16 = phi i32 [ %13, %7 ], [ 23, %4 ]
%17 = add i32 %5, 3
%18 = add i32 %17, %16
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = sext i32 %1 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = sext i32 %5 to i64
%25 = tail call i8* @strncpy(i8* dereferenceable(1) %21, i8* %23, i64 %24)
%26 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 58, i8* %26
%27 = add nsw i32 %5, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %21, i64 %28
store i8 32, i8* %29
%30 = getelementptr inbounds i8, i8* %26, i64 2
%31 = tail call i8* @strcpy(i8* %30, i8* dereferenceable(1) %15)
ret i8* %21
}