#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 /*<<< orphan*/ sprintf(char *, char *, unsigned short, unsigned short,
                           unsigned short, unsigned short);
void ip_to_str(unsigned long addr, char *str) {
  if (!str)
    return;
  unsigned short a = 0xff & addr;
  unsigned short b = 0xff & (addr >> 8);
  unsigned short c = 0xff & (addr >> 16);
  unsigned short d = 0xff & (addr >> 24);
  sprintf(str, "%u.%u.%u.%u", a, b, c, d);
}


x86 assembly (clang, -O0):
<ip_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1130 <ip_to_str+0x20>
jmp    119f <ip_to_str+0x8f>
mov    -0x8(%rbp),%rax
and    $0xff,%rax
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %ax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %ax,-0x16(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x18,%rax
and    $0xff,%rax
mov    %ax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x12(%rbp),%dx
mov    -0x14(%rbp),%cx
mov    -0x16(%rbp),%ax
lea    0xe75(%rip),%rsi
movzwl %dx,%edx
movzwl %cx,%ecx
movzwl %ax,%r8d
movzwl -0x18(%rbp),%r9d
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_to_str>:
test   %rsi,%rsi
je     1141 <ip_to_str+0x31>
push   %rbx
mov    %rdi,%rax
movzbl %ah,%ecx
shr    $0x10,%edi
mov    %eax,%ebx
shr    $0x18,%ebx
movzbl %al,%edx
movzbl %dil,%r8d
lea    0xece(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %ebx,%r9d
pop    %rbx
jmp    1030 <sprintf@plt>
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define void @ip_to_str(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
store i64 %0, i64* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
br label %34
12: ; preds = %2
%13 = load i64, i64* %3
%14 = and i64 255, %13
%15 = trunc i64 %14 to i16
store i16 %15, i16* %5
%16 = load i64, i64* %3
%17 = lshr i64 %16, 8
%18 = and i64 255, %17
%19 = trunc i64 %18 to i16
store i16 %19, i16* %6
%20 = load i64, i64* %3
%21 = lshr i64 %20, 16
%22 = and i64 255, %21
%23 = trunc i64 %22 to i16
store i16 %23, i16* %7
%24 = load i64, i64* %3
%25 = lshr i64 %24, 24
%26 = and i64 255, %25
%27 = trunc i64 %26 to i16
store i16 %27, i16* %8
%28 = load i8*, i8** %4
%29 = load i16, i16* %5
%30 = load i16, i16* %6
%31 = load i16, i16* %7
%32 = load i16, i16* %8
%33 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i16 zeroext %29, i16 zeroext %30, i16 zeroext %31, i16 zeroext %32)
br label %34
34: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define void @ip_to_str(i64 %0, i8* writeonly %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = trunc i64 %0 to i16
%6 = and i16 %5, 255
%7 = lshr i16 %5, 8
%8 = lshr i64 %0, 16
%9 = trunc i64 %8 to i16
%10 = and i16 %9, 255
%11 = lshr i64 %0, 24
%12 = trunc i64 %11 to i16
%13 = and i16 %12, 255
%14 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i16 zeroext %6, i16 zeroext %7, i16 zeroext %10, i16 zeroext %13)
br label %15
15: ; preds = %2, %4
ret void
}