#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__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *strcat(char *, char *);
void ip2str(unsigned int address, char **rr) {
  int i;
  char *hlp, hlp2[5];
  unsigned char *addrp = (unsigned char *)&address;
  hlp = (char *)malloc(18);
  hlp[0] = '\0';
  for (i = 0; i < 3; i++) {
    sprintf(hlp2, "%i.", addrp[i]);
    hlp = strcat(hlp, (char *)hlp2);
  }
  sprintf(hlp2, "%i", addrp[3]);
  hlp = strcat(hlp, hlp2);
  *rr = hlp;
}


x86 assembly (clang, -O0):
<ip2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x12,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11a8 <ip2str+0x78>
lea    -0x25(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe80(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x25(%rbp),%rsi
call   1040 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <ip2str+0x33>
lea    -0x25(%rbp),%rdi
mov    -0x30(%rbp),%rax
lea    0xe4d(%rip),%rsi
movzbl 0x3(%rax),%edx
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x25(%rbp),%rsi
call   1040 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%ebx
mov    %edi,%r13d
shr    $0x10,%r13d
mov    %edi,%r14d
shr    $0x18,%r14d
mov    $0x12,%edi
call   1030 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
movzbl %bl,%edx
lea    0xe93(%rip),%r12
lea    0x13(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
movzbl %bh,%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
movzbl %r13b,%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
mov    0x8(%rsp),%rax
mov    %rbp,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%i.\00"
@.str.1 = [3 x i8] c"%i\00"
define void @ip2str(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [5 x i8]
%8 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = bitcast i32* %3 to i8*
store i8* %9, i8** %8
%10 = call i64 @malloc(i32 18)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
store i32 0, i32* %5
br label %14
14: ; preds = %28, %2
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %8
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %23)
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%27 = call i8* @strcat(i8* %25, i8* %26)
store i8* %27, i8** %6
br label %28
28: ; preds = %17
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %14
31: ; preds = %14
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 3
%35 = load i8, i8* %34
%36 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %35)
%37 = load i8*, i8** %6
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%39 = call i8* @strcat(i8* %37, i8* %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = load i8**, i8*** %4
store i8* %40, i8** %41
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%i.\00"
@.str.1 = [3 x i8] c"%i\00"
define void @ip2str(i32 %0, i8** nocapture writeonly %1) {
%3 = alloca [5 x i8]
%4 = trunc i32 %0 to i8
%5 = lshr i32 %0, 8
%6 = trunc i32 %5 to i8
%7 = lshr i32 %0, 16
%8 = trunc i32 %7 to i8
%9 = lshr i32 %0, 24
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%12 = tail call i64 @malloc(i32 18)
%13 = inttoptr i64 %12 to i8*
store i8 0, i8* %13
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %4)
%15 = call i8* @strcat(i8* dereferenceable(1) %13, i8* %11)
%16 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
%17 = call i8* @strcat(i8* dereferenceable(1) %13, i8* %11)
%18 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %8)
%19 = call i8* @strcat(i8* dereferenceable(1) %13, i8* %11)
%20 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %10)
%21 = call i8* @strcat(i8* dereferenceable(1) %13, i8* %11)
store i8* %13, i8** %1
ret void
}