#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 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;
  sprintf(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    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%r8b
mov    -0x10(%rbp),%rax
lea    0x2efd(%rip),%rdi
lea    0xeb6(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl 0x3(%rax),%r9d
call   1030 <sprintf@plt>
lea    0x2edb(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_sprintf>:
push   %rbx
mov    %edi,%ecx
mov    %edi,%esi
shr    $0x10,%esi
mov    %edi,%eax
shr    $0x18,%eax
movzbl %cl,%edx
movzbl %ch,%ecx
movzbl %sil,%r8d
lea    0x2f12(%rip),%rbx
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%r9d
call   1030 <sprintf@plt>
mov    %rbx,%rax
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 @sprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0), 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 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @ip_sprintf.ipbuf, i64 0, i64 0), i8* dereferenceable(1) 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)
}