char *ctrl(c)
int c;
{
  static char s[3];
  if (c < 040 || c == 0177) {
    s[0] = '^';
    s[1] = c == 0177 ? '?' : c + 'A' - 1;
    s[2] = '\0';
  } else {
    s[0] = c;
    s[1] = '\0';
  }
  return (s);
}


x86 assembly (clang, -O0):
<ctrl>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x20,-0x4(%rbp)
jl     111b <ctrl+0x1b>
cmpl   $0x7f,-0x4(%rbp)
jne    115a <ctrl+0x5a>
movb   $0x5e,0x2eff(%rip)
cmpl   $0x7f,-0x4(%rbp)
jne    1139 <ctrl+0x39>
mov    $0x3f,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <ctrl+0x45>
mov    -0x4(%rbp),%eax
add    $0x41,%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,0x2ed4(%rip)
movb   $0x0,0x2ece(%rip)
jmp    116a <ctrl+0x6a>
mov    -0x4(%rbp),%eax
mov    %al,0x2ebe(%rip)
movb   $0x0,0x2eb8(%rip)
lea    0x2eb0(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctrl>:
cmp    $0x20,%edi
jl     111a <ctrl+0x1a>
cmp    $0x7f,%edi
je     111a <ctrl+0x1a>
mov    %dil,0x2f10(%rip)
lea    0x2f0a(%rip),%rax
jmp    113f <ctrl+0x3f>
lea    0x40(%rdi),%eax
cmp    $0x7f,%edi
movb   $0x5e,0x2efa(%rip)
movzbl %al,%eax
mov    $0x3f,%ecx
cmovne %eax,%ecx
mov    %cl,0x2eea(%rip)
lea    0x2ee4(%rip),%rax
movb   $0x0,(%rax)
lea    0x2ed8(%rip),%rax
ret

LLVM IR (-O0):
@ctrl.s = internal global [3 x i8] zeroinitializer
define i8* @ctrl(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 32
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 127
br i1 %7, label %8, label %19
8: ; preds = %5, %1
store i8 94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 127
br i1 %10, label %11, label %12
11: ; preds = %8
br label %16
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 65
%15 = sub nsw i32 %14, 1
br label %16
16: ; preds = %12, %11
%17 = phi i32 [ 63, %11 ], [ %15, %12 ]
%18 = trunc i32 %17 to i8
store i8 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
store i8 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 2)
br label %22
19: ; preds = %5
%20 = load i32, i32* %2
%21 = trunc i32 %20 to i8
store i8 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
br label %22
22: ; preds = %19, %16
ret i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
}

LLVM IR (-O2):
@ctrl.s = internal global [3 x i8] zeroinitializer
define i8* @ctrl(i32 %0) {
%2 = icmp slt i32 %0, 32
%3 = icmp eq i32 %0, 127
%4 = or i1 %2, %3
br i1 %4, label %5, label %9
5: ; preds = %1
store i8 94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
%6 = trunc i32 %0 to i8
%7 = add i8 %6, 64
%8 = select i1 %3, i8 63, i8 %7
store i8 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
br label %11
9: ; preds = %1
%10 = trunc i32 %0 to i8
store i8 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
br label %11
11: ; preds = %9, %5
%12 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1), %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 2), %5 ]
store i8 0, i8* %12
ret i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
}