#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*/ ipbuf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char, unsigned char,
                            unsigned char, unsigned char);
const char *ip_sprintf(const unsigned int ip) {
  static char ipbuf[18];
  unsigned char *cip = (unsigned char *)&ip;
  snprintf(ipbuf, sizeof(ipbuf), "%d.%d.%d.%d", cip[0], cip[1], cip[2], cip[3]);
  return ipbuf;
}


x86 assembly (clang, -O0):
<ip_sprintf>:
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    $0x12,%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):
<ip_sprintf>:
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    $0x12,%esi
mov    %eax,%r8d
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ip_sprintf.ipbuf = internal global [18 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ip_sprintf(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 ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0), i32 18, 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 ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@ip_sprintf.ipbuf = internal global [18 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ip_sprintf(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 ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0), i32 18, 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 ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0)
}