#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 */
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
typedef int in_addr_t;

/* Variables and functions */
char *_int10tostr(char *, int);
int ntohl(int /*<<< orphan*/);
char *inet_ntoa_r(struct in_addr in, char buf[16]) {
  in_addr_t addr = ntohl(in.s_addr);
  int i;
  char *p, *q;
  q = 0;
  p = buf + 16 - 1;
  for (i = 0; i < 4; i++) {
    p = _int10tostr(p, addr & 0xff) - 1;
    addr >>= 8;
    if (q) {
      *q = '.';
    }
    q = p;
  }
  return p + 1;
}


x86 assembly (clang, -O0):
<inet_ntoa_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <ntohl@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11ae <inet_ntoa_r+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
and    $0xff,%esi
call   1040 <_int10tostr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1198 <inet_ntoa_r+0x78>
mov    -0x28(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <inet_ntoa_r+0x39>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_ntoa_r>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1030 <ntohl@plt>
mov    %eax,%ebx
add    $0xf,%r14
movzbl %bl,%esi
mov    %r14,%rdi
call   1040 <_int10tostr@plt>
mov    %rax,%r14
lea    -0x1(%rax),%rdi
movzbl %bh,%esi
call   1040 <_int10tostr@plt>
mov    %rax,%r15
lea    -0x1(%rax),%rdi
mov    %ebx,%eax
shr    $0x10,%eax
movb   $0x2e,-0x1(%r14)
movzbl %al,%esi
call   1040 <_int10tostr@plt>
mov    %rax,%r14
lea    -0x1(%rax),%rdi
shr    $0x18,%ebx
movb   $0x2e,-0x1(%r15)
mov    %ebx,%esi
call   1040 <_int10tostr@plt>
movb   $0x2e,-0x1(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i8* @inet_ntoa_r(i32 %0, i8* %1) {
%3 = alloca %struct.in_addr
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %0, i32* %9
store i8* %1, i8** %4
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @ntohl(i32 %11)
store i32 %12, i32* %5
store i8* null, i8** %8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 16
%15 = getelementptr inbounds i8, i8* %14, i64 -1
store i8* %15, i8** %7
store i32 0, i32* %6
br label %16
16: ; preds = %33, %2
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = load i32, i32* %5
%22 = and i32 %21, 255
%23 = call i8* @_int10tostr(i8* %20, i32 %22)
%24 = getelementptr inbounds i8, i8* %23, i64 -1
store i8* %24, i8** %7
%25 = load i32, i32* %5
%26 = ashr i32 %25, 8
store i32 %26, i32* %5
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = load i8*, i8** %8
store i8 46, i8* %30
br label %31
31: ; preds = %29, %19
%32 = load i8*, i8** %7
store i8* %32, i8** %8
br label %33
33: ; preds = %31
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %16
36: ; preds = %16
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 1
ret i8* %38
}

LLVM IR (-O2):
define i8* @inet_ntoa_r(i32 %0, i8* %1) {
%3 = tail call i32 @ntohl(i32 %0)
%4 = getelementptr inbounds i8, i8* %1, i64 15
%5 = and i32 %3, 255
%6 = tail call i8* @_int10tostr(i8* %4, i32 %5)
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = lshr i32 %3, 8
%9 = and i32 %8, 255
%10 = tail call i8* @_int10tostr(i8* %7, i32 %9)
%11 = getelementptr inbounds i8, i8* %10, i64 -1
%12 = lshr i32 %3, 16
store i8 46, i8* %7
%13 = and i32 %12, 255
%14 = tail call i8* @_int10tostr(i8* %11, i32 %13)
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = lshr i32 %3, 24
store i8 46, i8* %11
%17 = tail call i8* @_int10tostr(i8* %15, i32 %16)
store i8 46, i8* %15
ret i8* %17
}