#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 */
int /*<<< orphan*/ assert(int);
void birch_to_lower(char *out, const char *buf, size_t sz) {
  char *map = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12"
              "\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&"
              "'()*+,-./"
              "0123456789:;<=>?@abcdefghijklmnopqrstuvwzyz{|}^_`"
              "abcdefghijklmnopqrstuvwzyz{|}~\x7f";
  size_t i;
  assert(buf != 0);
  assert(out != 0);
  for (i = 0; i < sz; i++)
    out[i] = map[buf[i] & 0x7f];
}


x86 assembly (clang, -O0):
<birch_to_lower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xed5(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119e <birch_to_lower+0x8e>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0x7f,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115b <birch_to_lower+0x4b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<birch_to_lower>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
test   %r15,%r15
je     11a4 <birch_to_lower+0x94>
cmp    $0x1,%r15
jne    1149 <birch_to_lower+0x39>
xor    %eax,%eax
jmp    1189 <birch_to_lower+0x79>
mov    %r15,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
lea    0xea7(%rip),%rdi
nopl   0x0(%rax)
movzbl (%rbx,%rax,1),%esi
and    $0x7f,%esi
movzbl (%rsi,%rdi,1),%edx
mov    %dl,(%r14,%rax,1)
movzbl 0x1(%rbx,%rax,1),%edx
and    $0x7f,%edx
movzbl (%rdx,%rdi,1),%edx
mov    %dl,0x1(%r14,%rax,1)
add    $0x2,%rax
cmp    %rax,%rcx
jne    1160 <birch_to_lower+0x50>
test   $0x1,%r15b
je     11a4 <birch_to_lower+0x94>
movzbl (%rbx,%rax,1),%ecx
and    $0x7f,%ecx
lea    0xe63(%rip),%rdx
mov    (%rcx,%rdx,1),%cl
mov    %cl,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [129 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F !\22#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwzyz{|}^_`abcdefghijklmnopqrstuvwzyz{|}~\7F\00"
define void @birch_to_lower(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
store i64 0, i64* %8
br label %17
17: ; preds = %35, %3
%18 = load i64, i64* %8
%19 = load i64, i64* %6
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = load i8*, i8** %5
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = and i32 %27, 127
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %22, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %4
%33 = load i64, i64* %8
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %21
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %17
38: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [129 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F !\22#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwzyz{|}^_`abcdefghijklmnopqrstuvwzyz{|}~\7F\00"
define void @birch_to_lower(i8* writeonly %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %1, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i8* %0, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i64 %2, 0
br i1 %10, label %48, label %11
11: ; preds = %3
%12 = and i64 %2, 1
%13 = icmp eq i64 %2, 1
br i1 %13, label %37, label %14
14: ; preds = %11
%15 = and i64 %2, -2
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 0, %14 ], [ %34, %16 ]
%18 = phi i64 [ 0, %14 ], [ %35, %16 ]
%19 = getelementptr inbounds i8, i8* %1, i64 %17
%20 = load i8, i8* %19
%21 = and i8 %20, 127
%22 = zext i8 %21 to i64
%23 = getelementptr inbounds [129 x i8], [129 x i8]* @.str, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %24, i8* %25
%26 = or i64 %17, 1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = load i8, i8* %27
%29 = and i8 %28, 127
%30 = zext i8 %29 to i64
%31 = getelementptr inbounds [129 x i8], [129 x i8]* @.str, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 %32, i8* %33
%34 = add nuw i64 %17, 2
%35 = add i64 %18, 2
%36 = icmp eq i64 %35, %15
br i1 %36, label %37, label %16
37: ; preds = %16, %11
%38 = phi i64 [ 0, %11 ], [ %34, %16 ]
%39 = icmp eq i64 %12, 0
br i1 %39, label %48, label %40
40: ; preds = %37
%41 = getelementptr inbounds i8, i8* %1, i64 %38
%42 = load i8, i8* %41
%43 = and i8 %42, 127
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [129 x i8], [129 x i8]* @.str, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %0, i64 %38
store i8 %46, i8* %47
br label %48
48: ; preds = %40, %37, %3
ret void
}