#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 */
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char);
char *addr_to_dotted(struct in_addr *addrp) {
  static char buf[20];
  unsigned char *bytep;
  bytep = (unsigned char *)&(addrp->s_addr);
  sprintf(buf, "%d.%d.%d.%d", bytep[0], bytep[1], bytep[2], bytep[3]);
  return buf;
}


x86 assembly (clang, -O0):
<addr_to_dotted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%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    0x2efc(%rip),%rdi
lea    0xeb5(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl 0x3(%rax),%r9d
call   1030 <sprintf@plt>
lea    0x2eda(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_to_dotted>:
push   %rbx
movzbl (%rdi),%edx
movzbl 0x1(%rdi),%ecx
movzbl 0x2(%rdi),%r8d
movzbl 0x3(%rdi),%r9d
lea    0x2f17(%rip),%rbx
lea    0xed0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@addr_to_dotted.buf = internal global [20 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @addr_to_dotted(%struct.in_addr* %0) {
%2 = alloca %struct.in_addr*
%3 = alloca i8*
store %struct.in_addr* %0, %struct.in_addr** %2
%4 = load %struct.in_addr*, %struct.in_addr** %2
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%6 = bitcast i32* %5 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 3
%18 = load i8, i8* %17
%19 = call i32 @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @addr_to_dotted.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 zeroext %12, i8 zeroext %15, i8 zeroext %18)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @addr_to_dotted.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@addr_to_dotted.buf = internal global [20 x i8] zeroinitializer
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @addr_to_dotted(%struct.in_addr* nocapture %0) {
%2 = bitcast %struct.in_addr* %0 to i8*
%3 = load i8, i8* %2
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = load i8, i8* %4
%6 = getelementptr inbounds i8, i8* %2, i64 2
%7 = load i8, i8* %6
%8 = getelementptr inbounds i8, i8* %2, i64 3
%9 = load i8, i8* %8
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @addr_to_dotted.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %3, i8 zeroext %5, i8 zeroext %7, i8 zeroext %9)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @addr_to_dotted.buf, i64 0, i64 0)
}