#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 uint32_t;

/* Variables and functions */
char *cast_uint_to_IPv4(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *);
uint32_t invert_IP(uint32_t ip) {
  char *_ip = cast_uint_to_IPv4(ip);
  uint32_t ipbytes[4];
  sscanf(_ip, "%u.%u.%u.%u", &ipbytes[3], &ipbytes[2], &ipbytes[1],
         &ipbytes[0]);
  free(_ip);
  return ipbytes[0] << 24 | ipbytes[1] << 16 | ipbytes[2] << 8 |
         ipbytes[3] << 0;
}


x86 assembly (clang, -O0):
<invert_IP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <cast_uint_to_IPv4@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
add    $0xc,%rdx
lea    -0x20(%rbp),%rcx
add    $0x8,%rcx
lea    -0x20(%rbp),%r8
add    $0x4,%r8
lea    -0x20(%rbp),%r9
lea    0xe92(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
shl    $0x18,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x14(%rbp),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert_IP>:
push   %rbx
sub    $0x10,%rsp
call   1040 <cast_uint_to_IPv4@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
lea    0xead(%rip),%rsi
mov    %rsp,%r9
mov    %rax,%rdi
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
shl    $0x18,%eax
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x8(%rsp),%eax
shl    $0x8,%eax
or     %ecx,%eax
or     0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @invert_IP(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i8* @cast_uint_to_IPv4(i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%12 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10, i32* %11)
%13 = load i8*, i8** %3
%14 = call i32 @free(i8* %13)
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%16 = load i32, i32* %15
%17 = shl i32 %16, 24
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%19 = load i32, i32* %18
%20 = shl i32 %19, 16
%21 = or i32 %17, %20
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%23 = load i32, i32* %22
%24 = shl i32 %23, 8
%25 = or i32 %21, %24
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%27 = load i32, i32* %26
%28 = shl i32 %27, 0
%29 = or i32 %25, %28
ret i32 %29
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @invert_IP(i32 %0) {
%2 = alloca [4 x i32]
%3 = tail call i8* @cast_uint_to_IPv4(i32 %0)
%4 = bitcast [4 x i32]* %2 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%9 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%10 = call i32 @free(i8* %3)
%11 = load i32, i32* %8
%12 = shl i32 %11, 24
%13 = load i32, i32* %7
%14 = shl i32 %13, 16
%15 = or i32 %14, %12
%16 = load i32, i32* %6
%17 = shl i32 %16, 8
%18 = or i32 %15, %17
%19 = load i32, i32* %5
%20 = or i32 %18, %19
ret i32 %20
}