#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 String_utoa(unsigned long, char *);
int iptostring(unsigned char *ip, char *ipstring) {
  int temp, i, length, uLength;
  char *ptr;
  ip = ip + 3;
  ptr = ipstring;
  uLength = 0;
  for (i = 0; i < 4; i++) {
    temp = *ip;
    length = String_utoa((unsigned long)temp, ptr);
    ptr = ptr + length;
    uLength += length;
    *ptr = '.';
    ptr++;
    uLength++;
    ip--;
  }
  return (uLength - 1);
}


x86 assembly (clang, -O0):
<iptostring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11b4 <iptostring+0xa4>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <String_utoa@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <iptostring+0x32>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptostring>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
movzbl 0x3(%rdi),%edi
call   1030 <String_utoa@plt>
movslq %eax,%r15
lea    (%rbx,%r15,1),%r12
movb   $0x2e,(%rbx,%r15,1)
lea    (%rbx,%r15,1),%rsi
add    $0x1,%rsi
movzbl 0x2(%r14),%edi
call   1030 <String_utoa@plt>
movslq %eax,%rbx
lea    (%rbx,%r12,1),%r13
add    $0x1,%r13
movb   $0x2e,0x1(%rbx,%r12,1)
lea    (%rbx,%r12,1),%rsi
add    $0x2,%rsi
add    %r15d,%ebx
movzbl 0x1(%r14),%edi
call   1030 <String_utoa@plt>
add    %eax,%ebx
cltq
lea    (%rax,%r13,1),%r15
add    $0x1,%r15
movb   $0x2e,0x1(%rax,%r13,1)
lea    (%rax,%r13,1),%rsi
add    $0x2,%rsi
movzbl (%r14),%edi
call   1030 <String_utoa@plt>
cltq
movb   $0x2e,0x1(%rax,%r15,1)
add    %ebx,%eax
add    $0x3,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @iptostring(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 3
store i8* %11, i8** %3
%12 = load i8*, i8** %4
store i8* %12, i8** %9
store i32 0, i32* %8
store i32 0, i32* %6
br label %13
13: ; preds = %38, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %41
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = load i8*, i8** %9
%23 = call i32 @String_utoa(i64 %21, i8* %22)
store i32 %23, i32* %7
%24 = load i8*, i8** %9
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8* %27, i8** %9
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = add nsw i32 %29, %28
store i32 %30, i32* %8
%31 = load i8*, i8** %9
store i8 46, i8* %31
%32 = load i8*, i8** %9
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %9
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %3
br label %38
38: ; preds = %16
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %13
41: ; preds = %13
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 1
ret i32 %43
}

LLVM IR (-O2):
define i32 @iptostring(i8* nocapture %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i64
%6 = tail call i32 @String_utoa(i64 %5, i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 46, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = zext i8 %11 to i64
%13 = tail call i32 @String_utoa(i64 %12, i8* %9)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
store i8 46, i8* %15
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = add i32 %6, 2
%18 = add i32 %17, %13
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i64
%22 = tail call i32 @String_utoa(i64 %21, i8* %16)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %16, i64 %23
store i8 46, i8* %24
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = add i32 %18, 1
%27 = add i32 %26, %22
%28 = load i8, i8* %0
%29 = zext i8 %28 to i64
%30 = tail call i32 @String_utoa(i64 %29, i8* %25)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %25, i64 %31
store i8 46, i8* %32
%33 = add i32 %27, %30
ret i32 %33
}