#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 */
struct sspm_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sspm_append_char(struct sspm_buffer *, char);
int /*<<< orphan*/ sspm_append_hex(struct sspm_buffer *, char);
int /*<<< orphan*/ sspm_append_string(struct sspm_buffer *, char *);
scalar_t__ sspm_is_printable(char);
void sspm_encode_quoted_printable(struct sspm_buffer *buf, char *data) {
  char *p;
  int lpos = 0;
  for (p = data; *p != 0; p++) {
    if (sspm_is_printable(*p)) {
      sspm_append_char(buf, *p);
      lpos++;
    } else if (*p == '\t' || *p == ' ') {
      char n = *(p + 1);
      if (n == '\n' || n == '\r') {
        sspm_append_hex(buf, *p);
        lpos += 3;
      } else {
        sspm_append_char(buf, *p);
        lpos++;
      }
    } else if (*p == '\n' || *p == '\r') {
      sspm_append_char(buf, *p);
      lpos = 0;
    } else {
      sspm_append_hex(buf, *p);
      lpos += 3;
    }
    if (lpos > 72) {
      lpos = 0;
      sspm_append_string(buf, "=\n");
    }
  }
}


x86 assembly (clang, -O0):
<sspm_encode_quoted_printable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12b9 <sspm_encode_quoted_printable+0x179>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <sspm_is_printable@plt>
cmp    $0x0,%rax
je     11a3 <sspm_encode_quoted_printable+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <sspm_append_char@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1282 <sspm_encode_quoted_printable+0x142>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     11c3 <sspm_encode_quoted_printable+0x83>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1223 <sspm_encode_quoted_printable+0xe3>
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
je     11e7 <sspm_encode_quoted_printable+0xa7>
movsbl -0x1d(%rbp),%eax
cmp    $0xd,%eax
jne    1205 <sspm_encode_quoted_printable+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1060 <sspm_append_hex@plt>
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1c(%rbp)
jmp    121e <sspm_encode_quoted_printable+0xde>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <sspm_append_char@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127d <sspm_encode_quoted_printable+0x13d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1243 <sspm_encode_quoted_printable+0x103>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    125f <sspm_encode_quoted_printable+0x11f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <sspm_append_char@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1278 <sspm_encode_quoted_printable+0x138>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1060 <sspm_append_hex@plt>
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1c(%rbp)
jmp    127d <sspm_encode_quoted_printable+0x13d>
jmp    1282 <sspm_encode_quoted_printable+0x142>
cmpl   $0x48,-0x1c(%rbp)
jle    12a3 <sspm_encode_quoted_printable+0x163>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd62(%rip),%rsi
call   1030 <sspm_append_string@plt>
jmp    12a8 <sspm_encode_quoted_printable+0x168>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115f <sspm_encode_quoted_printable+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sspm_encode_quoted_printable>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rsi),%al
test   %al,%al
je     11f2 <sspm_encode_quoted_printable+0xb2>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
xor    %ebp,%ebp
lea    0xe9b(%rip),%r12
lea    0xef4(%rip),%r15
jmp    1186 <sspm_encode_quoted_printable+0x46>
movsbl %cl,%esi
mov    %r14,%rdi
call   1050 <sspm_append_char@plt>
xor    %ebp,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11f2 <sspm_encode_quoted_printable+0xb2>
movsbl %al,%edi
call   1040 <sspm_is_printable@plt>
movzbl -0x1(%rbx),%ecx
test   %rax,%rax
je     11b0 <sspm_encode_quoted_printable+0x70>
movsbl %cl,%esi
mov    %r14,%rdi
call   1050 <sspm_append_char@plt>
mov    $0x1,%eax
jmp    11de <sspm_encode_quoted_printable+0x9e>
nopl   0x0(%rax)
lea    -0x9(%rcx),%eax
cmp    $0x17,%al
ja     11ce <sspm_encode_quoted_printable+0x8e>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
movzbl (%rbx),%eax
cmp    $0xd,%al
je     11ce <sspm_encode_quoted_printable+0x8e>
cmp    $0xa,%al
jne    1197 <sspm_encode_quoted_printable+0x57>
movsbl %cl,%esi
mov    %r14,%rdi
call   1060 <sspm_append_hex@plt>
mov    $0x3,%eax
add    %eax,%ebp
cmp    $0x49,%ebp
jl     117b <sspm_encode_quoted_printable+0x3b>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <sspm_append_string@plt>
jmp    1179 <sspm_encode_quoted_printable+0x39>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sspm_buffer = type { i32 }
@.str = [3 x i8] c"=\0A\00"
define void @sspm_encode_quoted_printable(%struct.sspm_buffer* %0, i8* %1) {
%3 = alloca %struct.sspm_buffer*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store %struct.sspm_buffer* %0, %struct.sspm_buffer** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %5
br label %9
9: ; preds = %93, %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %96
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = call i64 @sspm_is_printable(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = call i32 @sspm_append_char(%struct.sspm_buffer* %20, i8 signext %22)
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %86
26: ; preds = %14
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 9
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 32
br i1 %35, label %36, label %62
36: ; preds = %31, %26
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
store i8 %39, i8* %7
%40 = load i8, i8* %7
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %47, label %43
43: ; preds = %36
%44 = load i8, i8* %7
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 13
br i1 %46, label %47, label %54
47: ; preds = %43, %36
%48 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%49 = load i8*, i8** %5
%50 = load i8, i8* %49
%51 = call i32 @sspm_append_hex(%struct.sspm_buffer* %48, i8 signext %50)
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 3
store i32 %53, i32* %6
br label %61
54: ; preds = %43
%55 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%56 = load i8*, i8** %5
%57 = load i8, i8* %56
%58 = call i32 @sspm_append_char(%struct.sspm_buffer* %55, i8 signext %57)
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %61
61: ; preds = %54, %47
br label %85
62: ; preds = %31
%63 = load i8*, i8** %5
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 10
br i1 %66, label %72, label %67
67: ; preds = %62
%68 = load i8*, i8** %5
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 13
br i1 %71, label %72, label %77
72: ; preds = %67, %62
%73 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%74 = load i8*, i8** %5
%75 = load i8, i8* %74
%76 = call i32 @sspm_append_char(%struct.sspm_buffer* %73, i8 signext %75)
store i32 0, i32* %6
br label %84
77: ; preds = %67
%78 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%79 = load i8*, i8** %5
%80 = load i8, i8* %79
%81 = call i32 @sspm_append_hex(%struct.sspm_buffer* %78, i8 signext %80)
%82 = load i32, i32* %6
%83 = add nsw i32 %82, 3
store i32 %83, i32* %6
br label %84
84: ; preds = %77, %72
br label %85
85: ; preds = %84, %61
br label %86
86: ; preds = %85, %19
%87 = load i32, i32* %6
%88 = icmp sgt i32 %87, 72
br i1 %88, label %89, label %92
89: ; preds = %86
store i32 0, i32* %6
%90 = load %struct.sspm_buffer*, %struct.sspm_buffer** %3
%91 = call i32 @sspm_append_string(%struct.sspm_buffer* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %92
92: ; preds = %89, %86
br label %93
93: ; preds = %92
%94 = load i8*, i8** %5
%95 = getelementptr inbounds i8, i8* %94, i32 1
store i8* %95, i8** %5
br label %9
96: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.sspm_buffer = type { i32 }
@.str = [3 x i8] c"=\0A\00"
define void @sspm_encode_quoted_printable(%struct.sspm_buffer* %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %37, label %5
5: ; preds = %2, %32
%6 = phi i8 [ %35, %32 ], [ %3, %2 ]
%7 = phi i8* [ %34, %32 ], [ %1, %2 ]
%8 = phi i32 [ %33, %32 ], [ 0, %2 ]
%9 = tail call i64 @sspm_is_printable(i8 signext %6)
%10 = icmp eq i64 %9, 0
%11 = load i8, i8* %7
br i1 %10, label %14, label %12
12: ; preds = %5
%13 = tail call i32 @sspm_append_char(%struct.sspm_buffer* %0, i8 signext %11)
br label %26
14: ; preds = %5
switch i8 %11, label %24 [
i8 9, label %15
i8 32, label %15
i8 10, label %22
i8 13, label %22
]
15: ; preds = %14, %14
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = load i8, i8* %16
switch i8 %17, label %20 [
i8 13, label %18
i8 10, label %18
]
18: ; preds = %15, %15
%19 = tail call i32 @sspm_append_hex(%struct.sspm_buffer* %0, i8 signext %11)
br label %26
20: ; preds = %15
%21 = tail call i32 @sspm_append_char(%struct.sspm_buffer* %0, i8 signext %11)
br label %26
22: ; preds = %14, %14
%23 = tail call i32 @sspm_append_char(%struct.sspm_buffer* %0, i8 signext %11)
br label %32
24: ; preds = %14
%25 = tail call i32 @sspm_append_hex(%struct.sspm_buffer* %0, i8 signext %11)
br label %26
26: ; preds = %18, %20, %24, %12
%27 = phi i32 [ 3, %18 ], [ 1, %20 ], [ 3, %24 ], [ 1, %12 ]
%28 = add nsw i32 %8, %27
%29 = icmp sgt i32 %28, 72
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @sspm_append_string(%struct.sspm_buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %22, %26, %30
%33 = phi i32 [ 0, %30 ], [ %28, %26 ], [ 0, %22 ]
%34 = getelementptr inbounds i8, i8* %7, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %5
37: ; preds = %32, %2
ret void
}