#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 */
int /*<<< orphan*/ free(char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
void prep_inaddr_arpa(char *dest, char *src) {
  char *copystr;
  char *tmp;
  char arpa_addr[256];
  char *token[4];
  int i = 0;
  char *ptr;
  memset(arpa_addr, 0, 256);
  if (src != NULL) {
    copystr = (char *)malloc(strlen(src));
    strcpy(copystr, src);
    ptr = strtok(copystr, ".");
    while (ptr != NULL) {
      token[i] = malloc(strlen(ptr));
      strcpy(token[i], ptr);
      i++;
      ptr = strtok(NULL, ".");
    }
    tmp = token[0];
    token[0] = token[3];
    token[3] = tmp;
    tmp = token[1];
    token[1] = token[2];
    token[2] = tmp;
    strcat(arpa_addr, token[0]);
    strcat(arpa_addr, ".");
    strcat(arpa_addr, token[1]);
    strcat(arpa_addr, ".");
    strcat(arpa_addr, token[2]);
    strcat(arpa_addr, ".");
    strcat(arpa_addr, token[3]);
    strcat(arpa_addr, ".");
    strcat(arpa_addr, "in-addr.arpa");
    strcpy(dest, arpa_addr);
    free(copystr);
  }
}


x86 assembly (clang, -O0):
<prep_inaddr_arpa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x144(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     1368 <prep_inaddr_arpa+0x1f8>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x150(%rbp)
cmpq   $0x0,-0x150(%rbp)
je     125c <prep_inaddr_arpa+0xec>
mov    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
movslq -0x144(%rbp),%rax
mov    %rcx,-0x140(%rbp,%rax,8)
ff
movslq -0x144(%rbp),%rax
mov    -0x140(%rbp,%rax,8),%rdi
ff
mov    -0x150(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb5(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x150(%rbp)
jmp    11e3 <prep_inaddr_arpa+0x73>
mov    -0x140(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xd3b(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xd15(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xcef(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xcc9(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xcb8(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prep_inaddr_arpa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
test   %rbx,%rbx
je     12c4 <prep_inaddr_arpa+0x154>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe3b(%rip),%rsi
mov    %r12,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
je     123a <prep_inaddr_arpa+0xca>
mov    %rax,%rbx
lea    0x10(%rsp),%rbp
lea    0xe1a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%rbp
test   %rax,%rax
jne    11f0 <prep_inaddr_arpa+0x80>
mov    0x10(%rsp),%r15
mov    0x18(%rsp),%r13
mov    0x28(%rsp),%rsi
mov    0x20(%rsp),%r14
jmp    123a <prep_inaddr_arpa+0xca>
mov    %rsi,0x10(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xdad(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
lea    0xd5b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"in-addr.arpa\00"
define void @prep_inaddr_arpa(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [4 x i8*]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast [4 x i8*]* %4 to i8*
%7 = call i32 @memset(i8* %5, i32 0, i32 256)
%8 = icmp eq i8* %1, null
br i1 %8, label %51, label %9
9: ; preds = %2
%10 = call i32 @strlen(i8* %1)
%11 = call i8* @malloc(i32 %10)
%12 = call i32 @strcpy(i8* %11, i8* %1)
%13 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %34, label %15
15: ; preds = %9, %15
%16 = phi i64 [ %22, %15 ], [ 0, %9 ]
%17 = phi i8* [ %23, %15 ], [ %13, %9 ]
%18 = call i32 @strlen(i8* %17)
%19 = call i8* @malloc(i32 %18)
%20 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %16
store i8* %19, i8** %20
%21 = call i32 @strcpy(i8* %19, i8* %17)
%22 = add nuw i64 %16, 1
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %15
25: ; preds = %15
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 3
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
%31 = load i8*, i8** %30
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
%33 = load i8*, i8** %32
br label %34
34: ; preds = %25, %9
%35 = phi i8* [ %33, %25 ], [ undef, %9 ]
%36 = phi i8* [ %31, %25 ], [ undef, %9 ]
%37 = phi i8* [ %29, %25 ], [ undef, %9 ]
%38 = phi i8* [ %27, %25 ], [ undef, %9 ]
%39 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* %37, i8** %39
%40 = call i32 @strcat(i8* %5, i8* %37)
%41 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @strcat(i8* %5, i8* %35)
%43 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @strcat(i8* %5, i8* %36)
%45 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @strcat(i8* %5, i8* %38)
%47 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 @strcpy(i8* %0, i8* %5)
%50 = call i32 @free(i8* %11)
br label %51
51: ; preds = %34, %2
ret void
}