#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 u_int8_t;
typedef int u_int32_t;

/* Variables and functions */
int ntohl(int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int addr_fprint(char *addr) {
  u_int8_t split[4];
  u_int32_t ip;
  u_int32_t *x = (u_int32_t *)addr;
  ip = ntohl(*x);
  split[0] = (ip & 0xff000000) >> 24;
  split[1] = (ip & 0x00ff0000) >> 16;
  split[2] = (ip & 0x0000ff00) >> 8;
  split[3] = (ip & 0x000000ff);
  printf("%d.%d.%d.%d", split[0], split[1], split[2], split[3]);
  return 0;
}


x86 assembly (clang, -O0):
<addr_fprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addr_fprint>:
push   %rax
mov    (%rdi),%edi
call   1040 <ntohl@plt>
mov    %eax,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
shr    $0x18,%eax
shr    $0x10,%edx
movzbl %dl,%edx
lea    0xebf(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @addr_fprint(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
%10 = call i32 @ntohl(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = and i32 %11, -16777216
%13 = lshr i32 %12, 24
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32 %13, i32* %14
%15 = load i32, i32* %4
%16 = and i32 %15, 16711680
%17 = ashr i32 %16, 16
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
store i32 %17, i32* %18
%19 = load i32, i32* %4
%20 = and i32 %19, 65280
%21 = ashr i32 %20, 8
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
store i32 %21, i32* %22
%23 = load i32, i32* %4
%24 = and i32 %23, 255
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
store i32 %24, i32* %25
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%33 = load i32, i32* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %29, i32 %31, i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @addr_fprint(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @ntohl(i32 %3)
%5 = lshr i32 %4, 24
%6 = lshr i32 %4, 16
%7 = and i32 %6, 255
%8 = lshr i32 %4, 8
%9 = and i32 %8, 255
%10 = and i32 %4, 255
%11 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7, i32 %9, i32 %10)
ret i32 0
}