#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 sprintf(char *, char *, int);
char *__num_to_addr_r(unsigned long ipnum, char *ptr) {
  char *cur_str;
  int octet[4];
  int num_chars_written, i;
  cur_str = ptr;
  for (i = 0; i < 4; i++) {
    octet[3 - i] = ipnum % 256;
    ipnum >>= 8;
  }
  for (i = 0; i < 4; i++) {
    num_chars_written = sprintf(cur_str, "%d", octet[i]);
    cur_str += num_chars_written;
    if (i < 3) {
      cur_str[0] = '.';
      cur_str++;
    }
  }
  return ptr;
}


x86 assembly (clang, -O0):
<__num_to_addr_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    116d <__num_to_addr_r+0x5d>
mov    -0x8(%rbp),%rax
and    $0xff,%rax
mov    %eax,%ecx
mov    $0x3,%eax
sub    -0x38(%rbp),%eax
cltq
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    112f <__num_to_addr_r+0x1f>
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    11da <__num_to_addr_r+0xca>
mov    -0x18(%rbp),%rdi
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe6f(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    11c7 <__num_to_addr_r+0xb7>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cc <__num_to_addr_r+0xbc>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1174 <__num_to_addr_r+0x64>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__num_to_addr_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%rdx
movzbl %dl,%eax
mov    %eax,0x4(%rsp)
movzbl %dh,%eax
mov    %eax,%r14d
mov    %edx,%eax
shr    $0x10,%eax
movzbl %al,%r12d
shr    $0x18,%edx
lea    0xebf(%rip),%r15
mov    %rsi,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
cltq
lea    (%rax,%r13,1),%rbp
movb   $0x2e,0x0(%r13,%rax,1)
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <sprintf@plt>
cltq
lea    (%rax,%rbp,1),%rbx
add    $0x1,%rbx
movb   $0x2e,0x1(%rax,%rbp,1)
lea    (%rax,%rbp,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <sprintf@plt>
cltq
movb   $0x2e,0x1(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
call   1030 <sprintf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @__num_to_addr_r(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %5
store i32 0, i32* %8
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i64, i64* %3
%15 = urem i64 %14, 256
%16 = trunc i64 %15 to i32
%17 = load i32, i32* %8
%18 = sub nsw i32 3, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %19
store i32 %16, i32* %20
%21 = load i64, i64* %3
%22 = lshr i64 %21, 8
store i64 %22, i64* %3
br label %23
23: ; preds = %13
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %10
26: ; preds = %10
store i32 0, i32* %8
br label %27
27: ; preds = %49, %26
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %52
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = load i8*, i8** %5
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %5
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %48
43: ; preds = %30
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 46, i8* %45
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %5
br label %48
48: ; preds = %43, %30
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %27
52: ; preds = %27
%53 = load i8*, i8** %4
ret i8* %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @__num_to_addr_r(i64 %0, i8* returned writeonly %1) {
%3 = trunc i64 %0 to i32
%4 = and i32 %3, 255
%5 = trunc i64 %0 to i32
%6 = lshr i32 %5, 8
%7 = and i32 %6, 255
%8 = trunc i64 %0 to i32
%9 = lshr i32 %8, 16
%10 = and i32 %9, 255
%11 = trunc i64 %0 to i32
%12 = lshr i32 %11, 24
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 46, i8* %15
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 46, i8* %19
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 46, i8* %23
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
ret i8* %1
}