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

/* Variables and functions */
char *inet_ntoa(struct in_addr);
int rand();
unsigned char *generate_random_ip_v4() {
  char first_byte = (rand() % 254) & 0xFF;
  char scond_byte = (rand() % 254) & 0xFF;
  char third_byte = (rand() % 254) & 0xFF;
  char fourt_byte = (rand() % 254) & 0xFF;
  uint32_t ip =
      ((((((((0x00000000 | first_byte) << 8) | scond_byte) << 8) | third_byte)
         << 8) |
        fourt_byte)
       << 8) |
      0x13;
  struct in_addr ip_addr;
  ip_addr.s_addr = ip;
  char *addr = inet_ntoa(ip_addr);
  return addr;
}


x86 assembly (clang, -O0):
<generate_random_ip_v4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0xff,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0xff,%edx
mov    %dl,%al
mov    %al,-0x2(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0xff,%edx
mov    %dl,%al
mov    %al,-0x3(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0xff,%edx
mov    %dl,%al
mov    %al,-0x4(%rbp)
movsbl -0x1(%rbp),%eax
or     $0x0,%eax
shl    $0x8,%eax
movsbl -0x2(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
movsbl -0x3(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
movsbl -0x4(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
or     $0x13,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_ip_v4>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <rand@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
mov    %ecx,%ebp
sub    %edx,%ebp
add    %ecx,%ebp
add    %eax,%ebp
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
shr    $0x7,%ebx
add    %ecx,%ebx
add    %ebx,%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %ecx,%ecx
add    %eax,%ecx
shl    $0x10,%ebp
movsbl %bl,%eax
shl    $0x8,%eax
movsbl %cl,%edi
or     %eax,%edi
or     %ebp,%edi
shl    $0x8,%edi
or     $0x13,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <inet_ntoa@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i8* @generate_random_ip_v4() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca %struct.in_addr
%7 = alloca i8*
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 254
%10 = and i32 %9, 255
%11 = trunc i32 %10 to i8
store i8 %11, i8* %1
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 254
%14 = and i32 %13, 255
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 254
%18 = and i32 %17, 255
%19 = trunc i32 %18 to i8
store i8 %19, i8* %3
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 254
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
store i8 %23, i8* %4
%24 = load i8, i8* %1
%25 = sext i8 %24 to i32
%26 = or i32 0, %25
%27 = shl i32 %26, 8
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = or i32 %27, %29
%31 = shl i32 %30, 8
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = or i32 %31, %33
%35 = shl i32 %34, 8
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = or i32 %35, %37
%39 = shl i32 %38, 8
%40 = or i32 %39, 19
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i8* @inet_ntoa(i32 %44)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
ret i8* %46
}

LLVM IR (-O2):
define i8* @generate_random_ip_v4() {
%1 = tail call i32 (...) @rand()
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 254
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 254
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 254
%8 = shl i32 %5, 24
%9 = shl nsw i32 %3, 16
%10 = ashr exact i32 %8, 16
%11 = or i32 %10, %9
%12 = shl i32 %7, 24
%13 = ashr exact i32 %12, 24
%14 = or i32 %11, %13
%15 = shl i32 %14, 8
%16 = or i32 %15, 19
%17 = tail call i8* @inet_ntoa(i32 %16)
ret i8* %17
}