#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 rand();
unsigned int generate_random_ip_v4() {
  char first_byte = (rand() % 254) & 0x7F;
  char scond_byte = (rand() % 254) & 0x7F;
  char third_byte = (rand() % 254) & 0x7F;
  char fourt_byte = (rand() % 254) & 0x7F;
  return (
      (((((((0x00000000 | first_byte) << 8) | scond_byte) << 8) | third_byte)
        << 8) |
       fourt_byte)
      << 8);
}


x86 assembly (clang, -O0):
<generate_random_ip_v4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0x7f,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0x7f,%edx
mov    %dl,%al
mov    %al,-0x2(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0x7f,%edx
mov    %dl,%al
mov    %al,-0x3(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xfe,%ecx
cltd
idiv   %ecx
and    $0x7f,%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
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_ip_v4>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
xor    %eax,%eax
call   1030 <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   1030 <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,%ebx
sub    %edx,%ebx
add    %ecx,%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1030 <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
and    $0x7f,%ecx
and    $0x7f,%ebp
shl    $0x10,%ebp
and    $0x7f,%ebx
shl    $0x8,%ebx
or     %ebp,%ebx
or     %ecx,%ebx
shl    $0x8,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @generate_random_ip_v4() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 254
%7 = and i32 %6, 127
%8 = trunc i32 %7 to i8
store i8 %8, i8* %1
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 254
%11 = and i32 %10, 127
%12 = trunc i32 %11 to i8
store i8 %12, i8* %2
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 254
%15 = and i32 %14, 127
%16 = trunc i32 %15 to i8
store i8 %16, i8* %3
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 254
%19 = and i32 %18, 127
%20 = trunc i32 %19 to i8
store i8 %20, i8* %4
%21 = load i8, i8* %1
%22 = sext i8 %21 to i32
%23 = or i32 0, %22
%24 = shl i32 %23, 8
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = or i32 %24, %26
%28 = shl i32 %27, 8
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = or i32 %28, %30
%32 = shl i32 %31, 8
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = or i32 %32, %34
%36 = shl i32 %35, 8
ret i32 %36
}

LLVM IR (-O2):
define i32 @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 = and i32 %7, 127
%9 = shl nsw i32 %3, 16
%10 = and i32 %9, 8323072
%11 = shl nsw i32 %5, 8
%12 = and i32 %11, 32512
%13 = or i32 %10, %12
%14 = or i32 %13, %8
%15 = shl nuw nsw i32 %14, 8
ret i32 %15
}