#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void pdkim_quoteprint(FILE *stream, char *data, int len, int lf) {
  int i;
  unsigned char *p = (unsigned char *)data;
  for (i = 0; i < len; i++) {
    int c = p[i];
    switch (c) {
    case ' ':
      fprintf(stream, "{SP}");
      break;
    case '\t':
      fprintf(stream, "{TB}");
      break;
    case '\r':
      fprintf(stream, "{CR}");
      break;
    case '\n':
      fprintf(stream, "{LF}");
      break;
    case '{':
      fprintf(stream, "{BO}");
      break;
    case '}':
      fprintf(stream, "{BC}");
      break;
    default:
      if ((c < 32) || (c > 127))
        fprintf(stream, "{%02x}", c);
      else
        fputc(c, stream);
      break;
    }
  }
  if (lf)
    fputc('\n', stream);
}


x86 assembly (clang, -O0):
<pdkim_quoteprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a8 <pdkim_quoteprint+0x188>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x9,%eax
je     11e0 <pdkim_quoteprint+0xc0>
jmp    1174 <pdkim_quoteprint+0x54>
mov    -0x30(%rbp),%eax
sub    $0xa,%eax
je     120e <pdkim_quoteprint+0xee>
jmp    1185 <pdkim_quoteprint+0x65>
mov    -0x30(%rbp),%eax
sub    $0xd,%eax
je     11f7 <pdkim_quoteprint+0xd7>
jmp    1196 <pdkim_quoteprint+0x76>
mov    -0x30(%rbp),%eax
sub    $0x20,%eax
je     11c9 <pdkim_quoteprint+0xa9>
jmp    11a7 <pdkim_quoteprint+0x87>
mov    -0x30(%rbp),%eax
sub    $0x7b,%eax
je     1225 <pdkim_quoteprint+0x105>
jmp    11b8 <pdkim_quoteprint+0x98>
mov    -0x30(%rbp),%eax
sub    $0x7d,%eax
je     123c <pdkim_quoteprint+0x11c>
jmp    1253 <pdkim_quoteprint+0x133>
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
mov    -0x8(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
mov    -0x8(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
mov    -0x8(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
mov    -0x8(%rbp),%rdi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
mov    -0x8(%rbp),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1295 <pdkim_quoteprint+0x175>
cmpl   $0x20,-0x2c(%rbp)
jl     1267 <pdkim_quoteprint+0x147>
cmpl   $0x7f,-0x2c(%rbp)
jle    1281 <pdkim_quoteprint+0x161>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1290 <pdkim_quoteprint+0x170>
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    1295 <pdkim_quoteprint+0x175>
jmp    129a <pdkim_quoteprint+0x17a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <pdkim_quoteprint+0x25>
cmpl   $0x0,-0x18(%rbp)
je     12c0 <pdkim_quoteprint+0x1a0>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdkim_quoteprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %rdi,%rbx
test   %edx,%edx
jle    1247 <pdkim_quoteprint+0x117>
mov    %rsi,%rbp
mov    %edx,%r13d
lea    0xea9(%rip),%r15
lea    0xf02(%rip),%r14
xor    %r12d,%r12d
jmp    1185 <pdkim_quoteprint+0x55>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     1247 <pdkim_quoteprint+0x117>
movzbl 0x0(%rbp,%r12,1),%eax
lea    -0x9(%rax),%ecx
cmp    $0x17,%cl
ja     11c0 <pdkim_quoteprint+0x90>
movzbl %cl,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xeb5(%rip),%rdi
jmp    1170 <pdkim_quoteprint+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x7b,%al
je     1221 <pdkim_quoteprint+0xf1>
cmp    $0x7d,%al
jne    11db <pdkim_quoteprint+0xab>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xea0(%rip),%rdi
jmp    1170 <pdkim_quoteprint+0x40>
cmp    $0x1f,%al
jg     1237 <pdkim_quoteprint+0x107>
movzbl %al,%edx
mov    %rbx,%rdi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1178 <pdkim_quoteprint+0x48>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xe69(%rip),%rdi
jmp    1170 <pdkim_quoteprint+0x40>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xe4e(%rip),%rdi
jmp    1170 <pdkim_quoteprint+0x40>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xe42(%rip),%rdi
jmp    1170 <pdkim_quoteprint+0x40>
movsbl %al,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    1178 <pdkim_quoteprint+0x48>
cmpl   $0x0,0x4(%rsp)
je     1269 <pdkim_quoteprint+0x139>
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"{SP}\00"
@.str.1 = [5 x i8] c"{TB}\00"
@.str.2 = [5 x i8] c"{CR}\00"
@.str.3 = [5 x i8] c"{LF}\00"
@.str.4 = [5 x i8] c"{BO}\00"
@.str.5 = [5 x i8] c"{BC}\00"
@.str.6 = [7 x i8] c"{%02x}\00"
define void @pdkim_quoteprint(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %6
store i8* %12, i8** %10
store i32 0, i32* %9
br label %13
13: ; preds = %60, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %63
17: ; preds = %13
%18 = load i8*, i8** %10
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
store i32 %23, i32* %11
%24 = load i32, i32* %11
switch i32 %24, label %43 [
i32 32, label %25
i32 9, label %28
i32 13, label %31
i32 10, label %34
i32 123, label %37
i32 125, label %40
]
25: ; preds = %17
%26 = load i32*, i32** %5
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %59
28: ; preds = %17
%29 = load i32*, i32** %5
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %59
31: ; preds = %17
%32 = load i32*, i32** %5
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %59
34: ; preds = %17
%35 = load i32*, i32** %5
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %59
37: ; preds = %17
%38 = load i32*, i32** %5
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %59
40: ; preds = %17
%41 = load i32*, i32** %5
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %59
43: ; preds = %17
%44 = load i32, i32* %11
%45 = icmp slt i32 %44, 32
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %11
%48 = icmp sgt i32 %47, 127
br i1 %48, label %49, label %53
49: ; preds = %46, %43
%50 = load i32*, i32** %5
%51 = load i32, i32* %11
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %58
53: ; preds = %46
%54 = load i32, i32* %11
%55 = trunc i32 %54 to i8
%56 = load i32*, i32** %5
%57 = call i32 @fputc(i8 signext %55, i32* %56)
br label %58
58: ; preds = %53, %49
br label %59
59: ; preds = %58, %40, %37, %34, %31, %28, %25
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %13
63: ; preds = %13
%64 = load i32, i32* %8
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32*, i32** %5
%68 = call i32 @fputc(i8 signext 10, i32* %67)
br label %69
69: ; preds = %66, %63
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"{SP}\00"
@.str.1 = [5 x i8] c"{TB}\00"
@.str.2 = [5 x i8] c"{CR}\00"
@.str.3 = [5 x i8] c"{LF}\00"
@.str.4 = [5 x i8] c"{BO}\00"
@.str.5 = [5 x i8] c"{BC}\00"
@.str.6 = [7 x i8] c"{%02x}\00"
define void @pdkim_quoteprint(i32* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %34
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %31
%9 = phi i64 [ 0, %6 ], [ %32, %31 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
switch i8 %11, label %25 [
i8 32, label %13
i8 9, label %15
i8 13, label %17
i8 10, label %19
i8 123, label %21
i8 125, label %23
]
13: ; preds = %8
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
15: ; preds = %8
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
17: ; preds = %8
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
19: ; preds = %8
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
21: ; preds = %8
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
23: ; preds = %8
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %31
25: ; preds = %8
%26 = icmp slt i8 %11, 32
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %12)
br label %31
29: ; preds = %25
%30 = tail call i32 @fputc(i8 signext %11, i32* %0)
br label %31
31: ; preds = %27, %29, %23, %21, %19, %17, %15, %13
%32 = add nuw nsw i64 %9, 1
%33 = icmp eq i64 %32, %7
br i1 %33, label %34, label %8
34: ; preds = %31, %4
%35 = icmp eq i32 %3, 0
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = tail call i32 @fputc(i8 signext 10, i32* %0)
br label %38
38: ; preds = %36, %34
ret void
}