#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 uint8_t;

/* Variables and functions */
int *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(int *, char const *, int);
int strcspn(char const *, char *);
scalar_t__ strlen(char const *);
uint8_t *rr_encode(const char *s) {
  if (!s)
    return (NULL);
  uint8_t *buf, *b, l = 0;
  const char *p = s;
  buf = malloc(strlen(s) + 2);
  if (!buf)
    return (NULL);
  for (b = buf, l = strcspn(p, "."); l > 0; l = *p ? strcspn(++p, ".") : 0) {
    *b = l;
    memcpy(b + 1, p, l);
    b += l + 1;
    p += l;
  }
  *b = 0;
  return (buf);
}


x86 assembly (clang, -O0):
<rr_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <rr_encode+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1266 <rr_encode+0x126>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <rr_encode+0x64>
movq   $0x0,-0x8(%rbp)
jmp    1266 <rr_encode+0x126>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1254 <rr_encode+0x114>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123f <rr_encode+0xff>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x30(%rbp)
lea    0xdce(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x34(%rbp)
jmp    1249 <rr_encode+0x109>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1249 <rr_encode+0x109>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11bf <rr_encode+0x7f>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rr_encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     11d5 <rr_encode+0x95>
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d5 <rr_encode+0x95>
mov    %rax,%r14
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
mov    %r14,%r12
test   %eax,%eax
jle    11cb <rr_encode+0x8b>
mov    %eax,%ebp
lea    0xe77(%rip),%r15
mov    %r14,%r12
nopl   0x0(%rax)
mov    %ebp,(%r12)
lea    0x4(%r12),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %ebp,%eax
lea    (%r12,%rax,4),%r12
add    $0x4,%r12
cmpb   $0x0,(%rbx,%rax,1)
je     11cb <rr_encode+0x8b>
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcspn@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1190 <rr_encode+0x50>
movl   $0x0,(%r12)
jmp    11d8 <rr_encode+0x98>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32* @rr_encode(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %30, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 2
%6 = tail call i32* @malloc(i64 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %30, label %8
8: ; preds = %3
%9 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8, %24
%12 = phi i8* [ %25, %24 ], [ %0, %8 ]
%13 = phi i32 [ %26, %24 ], [ %9, %8 ]
%14 = phi i32* [ %19, %24 ], [ %6, %8 ]
store i32 %13, i32* %14
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = tail call i32 @memcpy(i32* %15, i8* %12, i32 %13)
%17 = add nuw nsw i32 %13, 1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %14, i64 %18
%20 = zext i32 %13 to i64
%21 = getelementptr inbounds i8, i8* %12, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %11
%25 = getelementptr inbounds i8, i8* %21, i64 1
%26 = tail call i32 @strcspn(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp sgt i32 %26, 0
br i1 %27, label %11, label %28
28: ; preds = %11, %24, %8
%29 = phi i32* [ %6, %8 ], [ %19, %24 ], [ %19, %11 ]
store i32 0, i32* %29
br label %30
30: ; preds = %28, %3, %1
%31 = phi i32* [ null, %1 ], [ %6, %28 ], [ null, %3 ]
ret i32* %31
}