#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*/ tempstring;
typedef int /*<<< orphan*/ resultstring;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int strlen(char *);
char *strtok_r(char *, char *, char **);
void string_to_reverse_dotted(char *string) {
  char resultstring[1024], tempstring[1024];
  char *token, *cptr, **ptrptr;
  int flag_first = 1;
  ptrptr = &cptr;
  snprintf(resultstring, sizeof(resultstring) - 1, "%s", "");
  if (string[0] == '.') {
    snprintf(tempstring, sizeof(tempstring) - 1, "%s.", resultstring);
    snprintf(resultstring, sizeof(resultstring) - 1, "%s", tempstring);
  };
  token = strtok_r(string, ".", ptrptr);
  while (token != NULL) {
    if (flag_first == 1) {
      snprintf(tempstring, sizeof(tempstring) - 1, "%s%s", token, resultstring);
      flag_first = 0;
    } else {
      snprintf(tempstring, sizeof(tempstring) - 1, "%s.%s", token,
               resultstring);
    };
    snprintf(resultstring, sizeof(resultstring) - 1, "%s", tempstring);
    token = strtok_r(NULL, ".", ptrptr);
  };
  if (string[strlen(string) - 1] == '.') {
    snprintf(tempstring, sizeof(tempstring) - 1, ".%s", resultstring);
    snprintf(resultstring, sizeof(resultstring) - 1, "%s", tempstring);
  };
  snprintf(string, 1024 - 1, ".%s", resultstring);
  return;
}


x86 assembly (clang, -O0):
<string_to_reverse_dotted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x82c(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x3ff,%esi
lea    0xea2(%rip),%rdx
lea    0xe92(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ca <string_to_reverse_dotted+0x9a>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xe5e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xe49(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x828(%rbp),%rdx
lea    0xe26(%rip),%rsi
call   1050 <strtok_r@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
je     12a6 <string_to_reverse_dotted+0x176>
cmpl   $0x1,-0x82c(%rbp)
jne    123a <string_to_reverse_dotted+0x10a>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rcx
lea    -0x410(%rbp),%r8
mov    $0x3ff,%esi
lea    0xde0(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
movl   $0x0,-0x82c(%rbp)
jmp    1262 <string_to_reverse_dotted+0x132>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rcx
lea    -0x410(%rbp),%r8
mov    $0x3ff,%esi
lea    0xdae(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xd90(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x828(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6d(%rip),%rsi
call   1050 <strtok_r@plt>
mov    %rax,-0x818(%rbp)
jmp    11e8 <string_to_reverse_dotted+0xb8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x838(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1318 <string_to_reverse_dotted+0x1e8>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xd1b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xcfb(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xcdc(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_reverse_dotted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdx
lea    0xeb1(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    $0x3ff,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
cmpb   $0x2e,(%rbx)
jne    11a7 <string_to_reverse_dotted+0x77>
lea    0xe91(%rip),%rdx
lea    0x410(%rsp),%r14
lea    0x10(%rsp),%rbp
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe77(%rip),%rdx
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe54(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     128f <string_to_reverse_dotted+0x15f>
lea    0xe36(%rip),%rdx
lea    0x410(%rsp),%rbx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %rax,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe15(%rip),%rdx
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xdf2(%rip),%rsi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     128f <string_to_reverse_dotted+0x15f>
lea    0xde3(%rip),%r15
lea    0x410(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xdd2(%rip),%r13
lea    0xdc1(%rip),%rbp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x3ff,%esi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
jne    1250 <string_to_reverse_dotted+0x120>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2e,-0x1(%rax,%rbx,1)
jne    12e4 <string_to_reverse_dotted+0x1b4>
lea    0xd5f(%rip),%rdx
lea    0x410(%rsp),%r14
lea    0x10(%rsp),%rbp
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd3a(%rip),%rdx
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd20(%rip),%rdx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x3ff,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"%s.\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [6 x i8] c"%s.%s\00"
@.str.6 = [4 x i8] c".%s\00"
define void @string_to_reverse_dotted(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 46
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1023, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %14
14: ; preds = %11, %1
%15 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %4)
%16 = icmp eq i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %14
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1023, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* %5)
%19 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%20 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %4)
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %17, %22
%23 = phi i8* [ %26, %22 ], [ %20, %17 ]
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %23, i8* %5)
%25 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%26 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %4)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %22
28: ; preds = %22, %17, %14
%29 = call i32 @strlen(i8* %0)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 46
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1023, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%37 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %38
38: ; preds = %35, %28
%39 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 1023, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %5)
ret void
}