#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *ipaddr2str(uint32_t ipaddr, char *buffer) {
  if (buffer != NULL) {
    register uint8_t a, b, c, d;
    a = (ipaddr & 0xFF000000) >> 24;
    b = (ipaddr & 0x00FF0000) >> 16;
    c = (ipaddr & 0x0000FF00) >> 8;
    d = (ipaddr & 0x000000FF);
    sprintf(buffer, "%u.%u.%u.%u", a, b, c, d);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<ipaddr2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117d <ipaddr2str+0x6d>
mov    -0x4(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xe88(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipaddr2str>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rsi,%rsi
je     1143 <ipaddr2str+0x33>
mov    %edi,%eax
mov    %edi,%edx
shr    $0x18,%edx
mov    %edi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
movzbl %ah,%ebp
movzbl %al,%r9d
lea    0xec8(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%r8d
call   1030 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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