#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 */
unsigned char petcii_fix_dupes(unsigned char);
unsigned char charset_p_topetcii(unsigned char c) {
  if (c == '\n') {
    return 0x0d;
  } else if (c == '\r') {
    return 0x0a;
  } else if (c <= 0x1f) {
    return 0x3f;
  } else if (c == '`') {
    return 0x27;
  } else if ((c >= 'a') && (c <= 'z')) {
    return (unsigned char)((c - 'a') + 0x41);
  } else if ((c >= 'A') && (c <= 'Z')) {
    return (unsigned char)((c - 'A') + 0xc1);
  } else if (c >= 0x7b) {
    return 0x3f;
  }
  return petcii_fix_dupes(c);
}


x86 assembly (clang, -O0):
<charset_p_topetcii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jne    1134 <charset_p_topetcii+0x24>
movb   $0xd,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0xd,%eax
jne    114a <charset_p_topetcii+0x3a>
movb   $0xa,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0x1f,%eax
jg     1160 <charset_p_topetcii+0x50>
movb   $0x3f,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0x60,%eax
jne    1176 <charset_p_topetcii+0x66>
movb   $0x27,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0x61,%eax
jl     11a2 <charset_p_topetcii+0x92>
movzbl -0x2(%rbp),%eax
cmp    $0x7a,%eax
jg     11a2 <charset_p_topetcii+0x92>
movzbl -0x2(%rbp),%eax
sub    $0x61,%eax
add    $0x41,%eax
mov    %al,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jl     11d0 <charset_p_topetcii+0xc0>
movzbl -0x2(%rbp),%eax
cmp    $0x5a,%eax
jg     11d0 <charset_p_topetcii+0xc0>
movzbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xc1,%eax
mov    %al,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
movzbl -0x2(%rbp),%eax
cmp    $0x7b,%eax
jl     11e6 <charset_p_topetcii+0xd6>
movb   $0x3f,-0x1(%rbp)
jmp    1210 <charset_p_topetcii+0x100>
jmp    11eb <charset_p_topetcii+0xdb>
jmp    11f0 <charset_p_topetcii+0xe0>
jmp    11f5 <charset_p_topetcii+0xe5>
jmp    11fa <charset_p_topetcii+0xea>
jmp    11ff <charset_p_topetcii+0xef>
jmp    1204 <charset_p_topetcii+0xf4>
movzbl -0x2(%rbp),%edi
call   1030 <petcii_fix_dupes@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charset_p_topetcii>:
cmp    $0xa,%dil
je     111f <charset_p_topetcii+0xf>
cmp    $0xd,%dil
jne    1122 <charset_p_topetcii+0x12>
mov    $0xa,%al
ret
mov    $0xd,%al
ret
mov    $0x3f,%al
cmp    $0x20,%dil
jb     1132 <charset_p_topetcii+0x22>
mov    $0x27,%al
cmp    $0x60,%dil
jne    1133 <charset_p_topetcii+0x23>
ret
lea    -0x61(%rdi),%eax
cmp    $0x19,%al
ja     1141 <charset_p_topetcii+0x31>
add    $0xe0,%dil
mov    %edi,%eax
ret
lea    -0x41(%rdi),%eax
cmp    $0x19,%al
ja     114f <charset_p_topetcii+0x3f>
xor    $0x80,%dil
mov    %edi,%eax
ret
mov    $0x3f,%al
cmp    $0x7a,%dil
ja     1132 <charset_p_topetcii+0x22>
movzbl %dil,%edi
jmp    1030 <petcii_fix_dupes@plt>

LLVM IR (-O0):
define zeroext i8 @charset_p_topetcii(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
%6 = icmp eq i32 %5, 10
br i1 %6, label %7, label %8
7: ; preds = %1
store i8 13, i8* %2
br label %65
8: ; preds = %1
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 13
br i1 %11, label %12, label %13
12: ; preds = %8
store i8 10, i8* %2
br label %65
13: ; preds = %8
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = icmp sle i32 %15, 31
br i1 %16, label %17, label %18
17: ; preds = %13
store i8 63, i8* %2
br label %65
18: ; preds = %13
%19 = load i8, i8* %3
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 96
br i1 %21, label %22, label %23
22: ; preds = %18
store i8 39, i8* %2
br label %65
23: ; preds = %18
%24 = load i8, i8* %3
%25 = zext i8 %24 to i32
%26 = icmp sge i32 %25, 97
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i8, i8* %3
%29 = zext i8 %28 to i32
%30 = icmp sle i32 %29, 122
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i8, i8* %3
%33 = zext i8 %32 to i32
%34 = sub nsw i32 %33, 97
%35 = add nsw i32 %34, 65
%36 = trunc i32 %35 to i8
store i8 %36, i8* %2
br label %65
37: ; preds = %27, %23
%38 = load i8, i8* %3
%39 = zext i8 %38 to i32
%40 = icmp sge i32 %39, 65
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i8, i8* %3
%43 = zext i8 %42 to i32
%44 = icmp sle i32 %43, 90
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i8, i8* %3
%47 = zext i8 %46 to i32
%48 = sub nsw i32 %47, 65
%49 = add nsw i32 %48, 193
%50 = trunc i32 %49 to i8
store i8 %50, i8* %2
br label %65
51: ; preds = %41, %37
%52 = load i8, i8* %3
%53 = zext i8 %52 to i32
%54 = icmp sge i32 %53, 123
br i1 %54, label %55, label %56
55: ; preds = %51
store i8 63, i8* %2
br label %65
56: ; preds = %51
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = load i8, i8* %3
%64 = call zeroext i8 @petcii_fix_dupes(i8 zeroext %63)
store i8 %64, i8* %2
br label %65
65: ; preds = %62, %55, %45, %31, %22, %17, %12, %7
%66 = load i8, i8* %2
ret i8 %66
}

LLVM IR (-O2):
define zeroext i8 @charset_p_topetcii(i8 zeroext %0) {
switch i8 %0, label %3 [
i8 10, label %21
i8 13, label %2
]
2: ; preds = %1
br label %21
3: ; preds = %1
%4 = icmp ult i8 %0, 32
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = icmp eq i8 %0, 96
br i1 %6, label %21, label %7
7: ; preds = %5
%8 = add i8 %0, -97
%9 = icmp ult i8 %8, 26
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = add nsw i8 %0, -32
br label %21
12: ; preds = %7
%13 = add i8 %0, -65
%14 = icmp ult i8 %13, 26
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = xor i8 %0, -128
br label %21
17: ; preds = %12
%18 = icmp ugt i8 %0, 122
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = tail call zeroext i8 @petcii_fix_dupes(i8 zeroext %0)
br label %21
21: ; preds = %17, %5, %3, %1, %19, %15, %10, %2
%22 = phi i8 [ 10, %2 ], [ %11, %10 ], [ %16, %15 ], [ %20, %19 ], [ 13, %1 ], [ 63, %3 ], [ 39, %5 ], [ 63, %17 ]
ret i8 %22
}