#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *fh_net_ntoa(uint32_t ipaddr) {
  static char b[18 * 10];
  static int buf_index = 0;
  register char *src, *dst;
  register int i = buf_index++ % 10;
  src = (char *)&ipaddr;
  dst = (char *)b + i * 18;
  sprintf(dst, "%d.%d.%d.%d", (((int)src[0]) & 0xff), (((int)src[1]) & 0xff),
          (((int)src[2]) & 0xff), (((int)src[3]) & 0xff));
  return dst;
}


x86 assembly (clang, -O0):
<fh_net_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2fd3(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2fc8(%rip)
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
imul   $0x12,-0x1c(%rbp),%eax
movslq %eax,%rcx
lea    0x2ef3(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%r8d
and    $0xff,%r8d
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%r9d
and    $0xff,%r9d
lea    0xe66(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fh_net_ntoa>:
push   %rbx
mov    %edi,%eax
movslq 0x2fda(%rip),%rcx
lea    0x1(%rcx),%edx
mov    %edx,0x2fd1(%rip)
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,8),%ecx
movslq %ecx,%rcx
lea    0x2ef3(%rip),%rbx
add    %rcx,%rbx
movzbl %al,%edx
movzbl %ah,%ecx
mov    %edi,%esi
shr    $0x10,%esi
movzbl %sil,%r8d
shr    $0x18,%eax
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%r9d
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@fh_net_ntoa.b = internal global [180 x i8] zeroinitializer
@fh_net_ntoa.buf_index = internal global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @fh_net_ntoa(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @fh_net_ntoa.buf_index
%7 = add nsw i32 %6, 1
store i32 %7, i32* @fh_net_ntoa.buf_index
%8 = srem i32 %6, 10
store i32 %8, i32* %5
%9 = bitcast i32* %2 to i8*
store i8* %9, i8** %3
%10 = load i32, i32* %5
%11 = mul nsw i32 %10, 18
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* getelementptr inbounds ([180 x i8], [180 x i8]* @fh_net_ntoa.b, i64 0, i64 0), i64 %12
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = and i32 %18, 255
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = and i32 %23, 255
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = and i32 %28, 255
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 3
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = and i32 %33, 255
%35 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %24, i32 %29, i32 %34)
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
@fh_net_ntoa.b = internal global [180 x i8] zeroinitializer
@fh_net_ntoa.buf_index = internal unnamed_addr global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @fh_net_ntoa(i32 %0) {
%2 = load i32, i32* @fh_net_ntoa.buf_index
%3 = add nsw i32 %2, 1
store i32 %3, i32* @fh_net_ntoa.buf_index
%4 = srem i32 %2, 10
%5 = mul nsw i32 %4, 18
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [180 x i8], [180 x i8]* @fh_net_ntoa.b, i64 0, i64 %6
%8 = and i32 %0, 255
%9 = lshr i32 %0, 8
%10 = and i32 %9, 255
%11 = lshr i32 %0, 16
%12 = and i32 %11, 255
%13 = lshr i32 %0, 24
%14 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10, i32 %12, i32 %13)
ret i8* %7
}