#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 */
char *malloc(int);
int sprintf(char *, char *, int);
char *GeoIP_num_to_addr(unsigned long ipnum) {
  char *ret_str;
  char *cur_str;
  int octet[4];
  int num_chars_written, i;
  ret_str = malloc(sizeof(char) * 16);
  cur_str = ret_str;
  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 ret_str;
}


x86 assembly (clang, -O0):
<GeoIP_num_to_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    1187 <GeoIP_num_to_addr+0x67>
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    1149 <GeoIP_num_to_addr+0x29>
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    11f4 <GeoIP_num_to_addr+0xd4>
mov    -0x18(%rbp),%rdi
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe55(%rip),%rsi
call   1040 <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    11e1 <GeoIP_num_to_addr+0xc1>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11e6 <GeoIP_num_to_addr+0xc6>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118e <GeoIP_num_to_addr+0x6e>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GeoIP_num_to_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,%r13
movzbl %bl,%eax
mov    %eax,0x4(%rsp)
movzbl %bh,%eax
mov    %eax,%r14d
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%r12d
shr    $0x18,%ebx
lea    0xea5(%rip),%r15
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <sprintf@plt>
cltq
lea    (%rax,%r13,1),%rbx
movb   $0x2e,0x0(%r13,%rax,1)
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <sprintf@plt>
cltq
lea    (%rax,%rbx,1),%rbp
add    $0x1,%rbp
movb   $0x2e,0x1(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <sprintf@plt>
cltq
movb   $0x2e,0x1(%rax,%rbp,1)
lea    (%rax,%rbp,1),%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
call   1040 <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* @GeoIP_num_to_addr(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4 x i32]
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %2
%8 = call i8* @malloc(i32 16)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
store i8* %9, i8** %4
store i32 0, i32* %7
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i64, i64* %2
%15 = urem i64 %14, 256
%16 = trunc i64 %15 to i32
%17 = load i32, i32* %7
%18 = sub nsw i32 3, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %19
store i32 %16, i32* %20
%21 = load i64, i64* %2
%22 = lshr i64 %21, 8
store i64 %22, i64* %2
br label %23
23: ; preds = %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %10
store i32 0, i32* %7
br label %27
27: ; preds = %49, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %52
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %5, 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* %6
%37 = load i32, i32* %6
%38 = load i8*, i8** %4
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %4
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %48
43: ; preds = %30
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 46, i8* %45
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
br label %48
48: ; preds = %43, %30
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %27
52: ; preds = %27
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define noalias i8* @GeoIP_num_to_addr(i64 %0) {
%2 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%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) %2, 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* %2, 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* %2
}