#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 */
scalar_t__ strncmp(char *, char *, int);
char *trim(char *);
char *string_decode_cr(char *d, char *s) {
  char *tmp = d;
  while (*s) {
    if (strncmp(s, "%0D", 3) == 0) {
      s += 3;
    } else if (strncmp(s, "%0A", 3) == 0) {
      *tmp++ = 10;
      s += 3;
    } else
      *tmp++ = *s++;
  }
  *tmp = '\0';
  return trim(d);
}


x86 assembly (clang, -O0):
<string_decode_cr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <string_decode_cr+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1175 <string_decode_cr+0x55>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    11de <string_decode_cr+0xbe>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b7 <string_decode_cr+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0xa,(%rax)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    11d9 <string_decode_cr+0xb9>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11de <string_decode_cr+0xbe>
jmp    1138 <string_decode_cr+0x18>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <trim@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_decode_cr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
cmpb   $0x0,(%rsi)
mov    %rdi,%r13
je     11a0 <string_decode_cr+0x80>
mov    %rsi,%rbx
lea    0xec2(%rip),%r15
lea    0xebf(%rip),%r12
mov    %r14,%r13
jmp    1162 <string_decode_cr+0x42>
nopw   0x0(%rax,%rax,1)
movb   $0xa,0x0(%r13)
add    $0x1,%r13
add    $0x3,%rbx
cmpb   $0x0,(%rbx)
je     11a0 <string_decode_cr+0x80>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1159 <string_decode_cr+0x39>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1150 <string_decode_cr+0x30>
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %al,0x0(%r13)
add    $0x1,%r13
cmpb   $0x0,(%rbx)
jne    1162 <string_decode_cr+0x42>
movb   $0x0,0x0(%r13)
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <trim@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%0D\00"
@.str.1 = [4 x i8] c"%0A\00"
define i8* @string_decode_cr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %34, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 3
store i8* %17, i8** %4
br label %34
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 10, i8* %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 3
store i8* %26, i8** %4
br label %33
27: ; preds = %18
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %28
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 %30, i8* %31
br label %33
33: ; preds = %27, %22
br label %34
34: ; preds = %33, %15
br label %7
35: ; preds = %7
%36 = load i8*, i8** %5
store i8 0, i8* %36
%37 = load i8*, i8** %3
%38 = call i8* @trim(i8* %37)
ret i8* %38
}

LLVM IR (-O2):
@.str = [4 x i8] c"%0D\00"
@.str.1 = [4 x i8] c"%0A\00"
define i8* @string_decode_cr(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2, %22
%6 = phi i8* [ %24, %22 ], [ %0, %2 ]
%7 = phi i8* [ %23, %22 ], [ %1, %2 ]
%8 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %7, i64 3
br label %22
12: ; preds = %5
%13 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %6, i64 1
store i8 10, i8* %6
%17 = getelementptr inbounds i8, i8* %7, i64 3
br label %22
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = load i8, i8* %7
%21 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %20, i8* %6
br label %22
22: ; preds = %15, %18, %10
%23 = phi i8* [ %11, %10 ], [ %17, %15 ], [ %19, %18 ]
%24 = phi i8* [ %6, %10 ], [ %16, %15 ], [ %21, %18 ]
%25 = load i8, i8* %23
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %5
27: ; preds = %22, %2
%28 = phi i8* [ %0, %2 ], [ %24, %22 ]
store i8 0, i8* %28
%29 = tail call i8* @trim(i8* %0)
ret i8* %29
}