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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char, unsigned char,
                            unsigned char, unsigned char);
char *ip2str(__be32 ip) {
  static char buf[16];
  unsigned char *p = (unsigned char *)&ip;
  snprintf(buf, sizeof(buf), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
  return buf;
}


x86 assembly (clang, -O0):
<ip2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%r9b
mov    -0x10(%rbp),%rax
lea    0x2efc(%rip),%rdi
mov    $0x10,%esi
lea    0xeb0(%rip),%rdx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl %r9b,%r9d
movzbl 0x3(%rax),%eax
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
lea    0x2ed2(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2str>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
mov    %edi,%edx
shr    $0x10,%edx
mov    %edi,%ecx
shr    $0x18,%ecx
mov    %ecx,(%rsp)
movzbl %al,%ecx
movzbl %ah,%eax
movzbl %dl,%r9d
lea    0x2f0b(%rip),%rbx
lea    0xec4(%rip),%rdx
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %eax,%r8d
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ip2str.buf = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ip2str(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = bitcast i32* %2 to i8*
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = load i8, i8* %12
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 3
%16 = load i8, i8* %15
%17 = call i32 @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ip2str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %7, i8 zeroext %10, i8 zeroext %13, i8 zeroext %16)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ip2str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@ip2str.buf = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ip2str(i32 %0) {
%2 = trunc i32 %0 to i8
%3 = lshr i32 %0, 8
%4 = trunc i32 %3 to i8
%5 = lshr i32 %0, 16
%6 = trunc i32 %5 to i8
%7 = lshr i32 %0, 24
%8 = trunc i32 %7 to i8
%9 = tail call i32 @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ip2str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %2, i8 zeroext %4, i8 zeroext %6, i8 zeroext %8)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ip2str.buf, i64 0, i64 0)
}