#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 */
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
char *defangIPaddr(char *address) {
  int len = strlen(address) + 6;
  char *defang = malloc(sizeof(char) * (len + 1));
  memset(defang, '0', len);
  defang[len] = '\0';
  char *p1 = defang, *p2 = address;
  while (*p2 != '\0') {
    if (*p2 == '.') {
      *p1++ = '[';
      *p1++ = '.';
      *p1++ = ']';
    } else {
      *p1++ = *p2;
    }
    p2++;
  }
  return defang;
}


x86 assembly (clang, -O0):
<defangIPaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x6,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x30,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1212 <defangIPaddr+0xe2>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ea <defangIPaddr+0xba>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5b,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5d,(%rax)
jmp    1201 <defangIPaddr+0xd1>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118f <defangIPaddr+0x5f>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<defangIPaddr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%r12
lea    0x6(%r12),%r15
lea    0x7(%r12),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x30,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
movb   $0x0,0x6(%r14,%r12,1)
mov    %r14,%rax
jmp    1181 <defangIPaddr+0x51>
movw   $0x2e5b,(%rax)
movb   $0x5d,0x2(%rax)
add    $0x3,%rax
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x2e,%cl
je     1170 <defangIPaddr+0x40>
test   %cl,%cl
je     1199 <defangIPaddr+0x69>
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%rbx
jmp    1181 <defangIPaddr+0x51>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @defangIPaddr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 6
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = call i32 @memset(i8* %16, i32 48, i32 %17)
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %4
store i8* %23, i8** %5
%24 = load i8*, i8** %2
store i8* %24, i8** %6
br label %25
25: ; preds = %47, %1
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 46
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
store i8 91, i8* %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
store i8 46, i8* %38
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %5
store i8 93, i8* %40
br label %47
42: ; preds = %30
%43 = load i8*, i8** %6
%44 = load i8, i8* %43
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %5
store i8 %44, i8* %45
br label %47
47: ; preds = %42, %35
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %6
br label %25
50: ; preds = %25
%51 = load i8*, i8** %4
ret i8* %51
}

LLVM IR (-O2):
define i8* @defangIPaddr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 6
%4 = add nsw i32 %2, 7
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @memset(i8* %5, i32 48, i32 %3)
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
br label %9
9: ; preds = %19, %1
%10 = phi i8* [ %5, %1 ], [ %20, %19 ]
%11 = phi i8* [ %0, %1 ], [ %21, %19 ]
%12 = load i8, i8* %11
switch i8 %12, label %17 [
i8 0, label %22
i8 46, label %13
]
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
store i8 91, i8* %10
%15 = getelementptr inbounds i8, i8* %10, i64 2
store i8 46, i8* %14
%16 = getelementptr inbounds i8, i8* %10, i64 3
store i8 93, i8* %15
br label %19
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %12, i8* %10
br label %19
19: ; preds = %17, %13
%20 = phi i8* [ %16, %13 ], [ %18, %17 ]
%21 = getelementptr inbounds i8, i8* %11, i64 1
br label %9
22: ; preds = %9
ret i8* %5
}