char *character(c)
int c;
{
  static char string[10];
  char *meta;
  meta = (c & 0x80) ? "M-" : "";
  c &= 0x7F;
  if (c < 32)
    snprintf(string, sizeof(string), "%s^%c", meta, (int)c + '@');
  else if (c == 127)
    snprintf(string, sizeof(string), "%s^?", meta);
  else
    snprintf(string, sizeof(string), "%s%c", meta, c);
  return (string);
}


x86 assembly (clang, -O0):
<character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
and    $0x80,%edx
lea    0xed7(%rip),%rax
lea    0xece(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x20,-0x4(%rbp)
jge    117b <character+0x6b>
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%r8d
add    $0x40,%r8d
lea    0x2ec6(%rip),%rdi
mov    $0xa,%esi
lea    0xe94(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11cf <character+0xbf>
cmpl   $0x7f,-0x4(%rbp)
jne    11a8 <character+0x98>
mov    -0x10(%rbp),%rcx
lea    0x2e99(%rip),%rdi
mov    $0xa,%esi
lea    0xe6d(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11ca <character+0xba>
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%r8d
lea    0x2e72(%rip),%rdi
mov    $0xa,%esi
lea    0xe4b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11cf <character+0xbf>
lea    0x2e53(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<character>:
push   %rax
mov    %edi,%r8d
test   $0x80,%r8b
lea    0xee3(%rip),%rax
lea    0xeda(%rip),%rcx
cmove  %rax,%rcx
and    $0x7f,%r8d
cmp    $0x1f,%r8d
ja     1148 <character+0x38>
add    $0x40,%r8d
lea    0x2eea(%rip),%rdi
lea    0xebd(%rip),%rdx
jmp    1171 <character+0x61>
lea    0x2eda(%rip),%rdi
cmp    $0x7f,%r8d
jne    116a <character+0x5a>
lea    0xead(%rip),%rdx
mov    $0xa,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    117d <character+0x6d>
lea    0xe9d(%rip),%rdx
mov    $0xa,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2ea5(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@character.string = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"M-\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"%s^%c\00"
@.str.3 = [5 x i8] c"%s^?\00"
@.str.4 = [5 x i8] c"%s%c\00"
define i8* @character(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = and i32 %4, 128
%6 = icmp ne i32 %5, 0
%7 = zext i1 %6 to i64
%8 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %8, i8** %3
%9 = load i32, i32* %2
%10 = and i32 %9, 127
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 32
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 64
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %16)
br label %29
18: ; preds = %1
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 127
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %28
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = load i32, i32* %2
%27 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %25, i32 %26)
br label %28
28: ; preds = %24, %21
br label %29
29: ; preds = %28, %13
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0)
}

LLVM IR (-O2):
@character.string = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"M-\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"%s^%c\00"
@.str.3 = [5 x i8] c"%s^?\00"
@.str.4 = [5 x i8] c"%s%c\00"
define i8* @character(i32 %0) {
%2 = and i32 %0, 128
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%5 = and i32 %0, 127
%6 = icmp ult i32 %5, 32
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = add nuw nsw i32 %5, 64
%9 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %8)
br label %16
10: ; preds = %1
%11 = icmp eq i32 %5, 127
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %16
14: ; preds = %10
%15 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0), i64 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %5)
br label %16
16: ; preds = %12, %14, %7
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @character.string, i64 0, i64 0)
}