#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*/ FILE;

/* Variables and functions */
int cp1251_to_unicode(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
void putrtf(FILE *rtf, char *str) {
  if (rtf)
    while (*str) {
      if (*str == '{' || *str == '}' || *str == '\\') {
        putc('\\', rtf);
        putc(*str++, rtf);
      } else if (isprint((unsigned char)*str)) {
        putc(*str++, rtf);
      } else {
        fprintf(rtf, "{\\u%u}", cp1251_to_unicode(*str++));
      }
    }
}


x86 assembly (clang, -O0):
<putrtf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1245 <putrtf+0x105>
jmp    1160 <putrtf+0x20>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1240 <putrtf+0x100>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
je     119d <putrtf+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7d,%eax
je     119d <putrtf+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11cd <putrtf+0x8d>
mov    -0x8(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    123b <putrtf+0xfb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1205 <putrtf+0xc5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
jmp    1236 <putrtf+0xf6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <cp1251_to_unicode@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xdcf(%rip),%rsi
call   1050 <fprintf@plt>
jmp    123b <putrtf+0xfb>
jmp    1160 <putrtf+0x20>
jmp    1245 <putrtf+0x105>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putrtf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11cc <putrtf+0x8c>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea6(%rip),%r15
movabs $0x280000001,%r12
jmp    118c <putrtf+0x4c>
cs nopw 0x0(%rax,%rax,1)
mov    $0x5c,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1040 <putc@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x5c(%rax),%ecx
cmp    $0x21,%cl
ja     11a0 <putrtf+0x60>
movzbl %cl,%ecx
bt     %rcx,%r12
jb     1170 <putrtf+0x30>
test   %al,%al
je     11cc <putrtf+0x8c>
movzbl %al,%edi
call   1060 <isprint@plt>
movsbl (%rbx),%edi
test   %rax,%rax
jne    1180 <putrtf+0x40>
call   1030 <cp1251_to_unicode@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
add    $0x1,%rbx
jmp    118c <putrtf+0x4c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"{\\u%u}\00"
define void @putrtf(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %57
7: ; preds = %2
br label %8
8: ; preds = %55, %7
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %56
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 123
br i1 %16, label %27, label %17
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 125
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 92
br i1 %26, label %27, label %35
27: ; preds = %22, %17, %12
%28 = load i32*, i32** %3
%29 = call i32 @putc(i8 signext 92, i32* %28)
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
%32 = load i8, i8* %30
%33 = load i32*, i32** %3
%34 = call i32 @putc(i8 signext %32, i32* %33)
br label %55
35: ; preds = %22
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = call i64 @isprint(i8 zeroext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
%43 = load i8, i8* %41
%44 = load i32*, i32** %3
%45 = call i32 @putc(i8 signext %43, i32* %44)
br label %54
46: ; preds = %35
%47 = load i32*, i32** %3
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
%50 = load i8, i8* %48
%51 = sext i8 %50 to i32
%52 = call i32 @cp1251_to_unicode(i32 %51)
%53 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %46, %40
br label %55
55: ; preds = %54, %27
br label %8
56: ; preds = %8
br label %57
57: ; preds = %56, %2
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"{\\u%u}\00"
define void @putrtf(i32* %0, i8* nocapture %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %23, label %4
4: ; preds = %2, %21
%5 = phi i8* [ %22, %21 ], [ %1, %2 ]
%6 = load i8, i8* %5
switch i8 %6, label %11 [
i8 0, label %23
i8 123, label %7
i8 125, label %7
i8 92, label %7
]
7: ; preds = %4, %4, %4
%8 = tail call i32 @putc(i8 signext 92, i32* %0)
%9 = load i8, i8* %5
%10 = tail call i32 @putc(i8 signext %9, i32* %0)
br label %21
11: ; preds = %4
%12 = tail call i64 @isprint(i8 zeroext %6)
%13 = icmp eq i64 %12, 0
%14 = load i8, i8* %5
br i1 %13, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @putc(i8 signext %14, i32* %0)
br label %21
17: ; preds = %11
%18 = sext i8 %14 to i32
%19 = tail call i32 @cp1251_to_unicode(i32 %18)
%20 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %15, %17, %7
%22 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
23: ; preds = %4, %2
ret void
}