#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 */
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *handle_char(char c) {
  char *s = malloc(3);
  memset(s, 0, 3);
  switch (c) {
  case '\n':
    strncpy(s, "\\n", 2);
    break;
  case '\t':
    strncpy(s, "\\t", 2);
    break;
  case '\r':
    strncpy(s, "\\r", 2);
    break;
  default:
    s[0] = c;
    break;
  }
  return s;
}


x86 assembly (clang, -O0):
<handle_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x3,%edi
mov    %edi,-0x18(%rbp)
call   1050 <malloc@plt>
mov    -0x18(%rbp),%edx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x9,%eax
je     11ae <handle_char+0x7e>
jmp    1172 <handle_char+0x42>
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
je     1194 <handle_char+0x64>
jmp    1183 <handle_char+0x53>
mov    -0x14(%rbp),%eax
sub    $0xd,%eax
je     11c8 <handle_char+0x98>
jmp    11e2 <handle_char+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    11eb <handle_char+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    11eb <handle_char+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    11eb <handle_char+0xbb>
mov    -0x1(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_char>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
cmp    $0x9,%ebp
je     1169 <handle_char+0x39>
cmp    $0xd,%ebp
je     1172 <handle_char+0x42>
cmp    $0xa,%ebp
jne    1188 <handle_char+0x58>
lea    0xe99(%rip),%rsi
jmp    1179 <handle_char+0x49>
lea    0xe93(%rip),%rsi
jmp    1179 <handle_char+0x49>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    118b <handle_char+0x5b>
mov    %bpl,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\r\00"
define i8* @handle_char(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8*
store i8 %0, i8* %2
%4 = call i8* @malloc(i32 3)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @memset(i8* %5, i32 0, i32 3)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %18 [
i32 10, label %9
i32 9, label %12
i32 13, label %15
]
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %22
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %22
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @strncpy(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %22
18: ; preds = %1
%19 = load i8, i8* %2
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 %19, i8* %21
br label %22
22: ; preds = %18, %15, %12, %9
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\r\00"
define i8* @handle_char(i8 signext %0) {
%2 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%3 = tail call i32 @memset(i8* %2, i32 0, i32 3)
%4 = sext i8 %0 to i32
switch i32 %4, label %11 [
i32 10, label %5
i32 9, label %7
i32 13, label %9
]
5: ; preds = %1
%6 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %12
7: ; preds = %1
%8 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %12
9: ; preds = %1
%10 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %12
11: ; preds = %1
store i8 %0, i8* %2
br label %12
12: ; preds = %11, %9, %7, %5
ret i8* %2
}