#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int const, int const, int const,
                           int const);
char *ipaddr_to_str(const uint32_t ipaddr) {
  static char ip_buf[16] = {0};
  memset(ip_buf, 0, 16);
  sprintf(ip_buf, "%u.%u.%u.%u", (ipaddr >> 24) & 0xFF, (ipaddr >> 16) & 0xFF,
          (ipaddr >> 8) & 0xFF, ipaddr & 0xFF);
  return ip_buf;
}


x86 assembly (clang, -O0):
<ipaddr_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f0e(%rip),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edx
sar    $0x18,%edx
and    $0xff,%edx
mov    -0x4(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x4(%rbp),%r8d
sar    $0x8,%r8d
and    $0xff,%r8d
mov    -0x4(%rbp),%r9d
and    $0xff,%r9d
lea    0x2ec9(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2eb6(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipaddr_to_str>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x2f13(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %ebx,%edx
shr    $0x18,%edx
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%ecx
movzbl %bh,%eax
movzbl %bl,%r9d
lea    0xea9(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%r8d
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ipaddr_to_str.ip_buf = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @ipaddr_to_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @memset(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0), i32 0, i32 16)
%4 = load i32, i32* %2
%5 = ashr i32 %4, 24
%6 = and i32 %5, 255
%7 = load i32, i32* %2
%8 = ashr i32 %7, 16
%9 = and i32 %8, 255
%10 = load i32, i32* %2
%11 = ashr i32 %10, 8
%12 = and i32 %11, 255
%13 = load i32, i32* %2
%14 = and i32 %13, 255
%15 = call i32 @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9, i32 %12, i32 %14)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0)
}

LLVM IR (-O2):
@ipaddr_to_str.ip_buf = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @ipaddr_to_str(i32 %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0), i32 0, i32 16)
%3 = lshr i32 %0, 24
%4 = lshr i32 %0, 16
%5 = and i32 %4, 255
%6 = lshr i32 %0, 8
%7 = and i32 %6, 255
%8 = and i32 %0, 255
%9 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5, i32 %7, i32 %8)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ipaddr_to_str.ip_buf, i64 0, i64 0)
}