#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 */
typedef int /*<<< orphan*/ suf;
typedef int /*<<< orphan*/ pre;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ isprint(char);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
const char *badch(const char *src, int errcode, char *errp, size_t errlen) {
  static const char pre[] = "unknown character (`";
  static const char suf[] = "') in input";
  char buf[5];
  struct sizecheck {
    char bigenough[40 - (sizeof(pre) - 1 + sizeof(buf) - 1 + sizeof(suf))];
  };
  char ch;
  if (errp == NULL ||
      errlen < (sizeof(pre) - 1 + sizeof(buf) - 1 + sizeof(suf)))
    return "unknown character in input";
  strcpy(errp, pre);
  ch = *(src + ((-4) - (errcode)));
  if (isprint(ch)) {
    buf[0] = ch;
    buf[1] = '\0';
  } else {
    buf[0] = '\\';
    buf[1] = ((ch & 0700) >> 6) + '0';
    buf[2] = ((ch & 0070) >> 3) + '0';
    buf[3] = ((ch & 0007) >> 0) + '0';
    buf[4] = '\0';
  }
  strcat(errp, buf);
  strcat(errp, suf);
  return (const char *)errp;
}


x86 assembly (clang, -O0):
<badch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115d <badch+0x2d>
cmpq   $0x24,-0x28(%rbp)
jae    116d <badch+0x3d>
lea    0xebd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1213 <badch+0xe3>
mov    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    $0xfffffffc,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2e(%rbp)
movsbl -0x2e(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11b4 <badch+0x84>
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
movb   $0x0,-0x2c(%rbp)
jmp    11ee <badch+0xbe>
movb   $0x5c,-0x2d(%rbp)
movsbl -0x2e(%rbp),%eax
and    $0x1c0,%eax
sar    $0x6,%eax
add    $0x30,%eax
mov    %al,-0x2c(%rbp)
movsbl -0x2e(%rbp),%eax
and    $0x38,%eax
sar    $0x3,%eax
add    $0x30,%eax
mov    %al,-0x2b(%rbp)
movsbl -0x2e(%rbp),%eax
and    $0x7,%eax
sar    $0x0,%eax
add    $0x30,%eax
mov    %al,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x2d(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<badch>:
lea    0xeea(%rip),%rax
test   %rdx,%rdx
je     11de <badch+0xae>
cmp    $0x24,%rcx
jb     11de <badch+0xae>
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcpy@plt>
movslq %ebp,%rax
sub    %rax,%rbx
mov    -0x4(%rbx),%bl
movsbl %bl,%edi
call   1040 <isprint@plt>
test   %rax,%rax
je     1187 <badch+0x57>
mov    %bl,0xb(%rsp)
xor    %eax,%eax
jmp    11b3 <badch+0x83>
movb   $0x5c,0xb(%rsp)
mov    %ebx,%eax
sar    $0x6,%al
and    $0x7,%al
or     $0x30,%al
mov    %ebx,%ecx
shr    $0x3,%cl
and    $0x7,%cl
or     $0x30,%cl
mov    %cl,0xd(%rsp)
and    $0x7,%bl
or     $0x30,%bl
mov    %bl,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %al,0xc(%rsp)
lea    0xb(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@badch.pre = internal constant [21 x i8] c"unknown character (`\00"
@badch.suf = internal constant [12 x i8] c"') in input\00"
@.str = [27 x i8] c"unknown character in input\00"
define i8* @badch(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [5 x i8]
%11 = alloca i8
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i64, i64* %9
%16 = icmp ult i64 %15, 36
br i1 %16, label %17, label %18
17: ; preds = %14, %4
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %5
br label %65
18: ; preds = %14
%19 = load i8*, i8** %8
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @badch.pre, i64 0, i64 0))
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = sub nsw i32 -4, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
store i8 %26, i8* %11
%27 = load i8, i8* %11
%28 = call i64 @isprint(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %18
%31 = load i8, i8* %11
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
store i8 %31, i8* %32
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 1
store i8 0, i8* %33
br label %58
34: ; preds = %18
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
store i8 92, i8* %35
%36 = load i8, i8* %11
%37 = sext i8 %36 to i32
%38 = and i32 %37, 448
%39 = ashr i32 %38, 6
%40 = add nsw i32 %39, 48
%41 = trunc i32 %40 to i8
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 1
store i8 %41, i8* %42
%43 = load i8, i8* %11
%44 = sext i8 %43 to i32
%45 = and i32 %44, 56
%46 = ashr i32 %45, 3
%47 = add nsw i32 %46, 48
%48 = trunc i32 %47 to i8
%49 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 2
store i8 %48, i8* %49
%50 = load i8, i8* %11
%51 = sext i8 %50 to i32
%52 = and i32 %51, 7
%53 = ashr i32 %52, 0
%54 = add nsw i32 %53, 48
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 3
store i8 %55, i8* %56
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 4
store i8 0, i8* %57
br label %58
58: ; preds = %34, %30
%59 = load i8*, i8** %8
%60 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%61 = call i32 @strcat(i8* %59, i8* %60)
%62 = load i8*, i8** %8
%63 = call i32 @strcat(i8* %62, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @badch.suf, i64 0, i64 0))
%64 = load i8*, i8** %8
store i8* %64, i8** %5
br label %65
65: ; preds = %58, %17
%66 = load i8*, i8** %5
ret i8* %66
}

LLVM IR (-O2):
@badch.pre = internal constant [21 x i8] c"unknown character (`\00"
@badch.suf = internal constant [12 x i8] c"') in input\00"
@.str = [27 x i8] c"unknown character in input\00"
define i8* @badch(i8* nocapture %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca [5 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %2, null
%8 = icmp ult i64 %3, 36
%9 = or i1 %7, %8
br i1 %9, label %36, label %10
10: ; preds = %4
%11 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @badch.pre, i64 0, i64 0))
%12 = sub nsw i32 -4, %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i64 @isprint(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %10
store i8 %15, i8* %6
br label %31
19: ; preds = %10
store i8 92, i8* %6
%20 = ashr i8 %15, 6
%21 = and i8 %20, 7
%22 = or i8 %21, 48
%23 = lshr i8 %15, 3
%24 = and i8 %23, 7
%25 = or i8 %24, 48
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
store i8 %25, i8* %26
%27 = and i8 %15, 7
%28 = or i8 %27, 48
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
store i8 %28, i8* %29
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 0, i8* %30
br label %31
31: ; preds = %19, %18
%32 = phi i8 [ %22, %19 ], [ 0, %18 ]
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
store i8 %32, i8* %33
%34 = call i32 @strcat(i8* %2, i8* %6)
%35 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @badch.suf, i64 0, i64 0))
br label %36
36: ; preds = %4, %31
%37 = phi i8* [ %2, %31 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %4 ]
ret i8* %37
}