#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 */
int /*<<< orphan*/ init_rand(int /*<<< orphan*/);
int rand_cmwc();
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generateRandomIPAddress(char *address) {
  init_rand(time(NULL));
  uint32_t random_num = rand_cmwc();
  char ipAddress[16];
  unsigned char oct1 = (random_num & 0xFF000000) >> 24,
                oct2 = (random_num & 0x00FF0000) >> 16,
                oct3 = (random_num & 0x0000FF00) >> 8,
                oct4 = (random_num & 0x000000FF);
  if (oct1 == 0) {
    oct1++;
  }
  if (oct4 == 0) {
    oct4++;
  }
  sprintf(ipAddress, "%u.%u.%u.%u", oct1, oct2, oct3, oct4);
  strcpy(address, ipAddress);
}


x86 assembly (clang, -O0):
<generateRandomIPAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1060 <init_rand@plt>
mov    $0x0,%al
call   1050 <rand_cmwc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x21(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %al,-0x22(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x23(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x24(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    11c0 <generateRandomIPAddress+0x70>
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
movzbl -0x24(%rbp),%eax
cmp    $0x0,%eax
jne    11d5 <generateRandomIPAddress+0x85>
mov    -0x24(%rbp),%al
add    $0x1,%al
mov    %al,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x21(%rbp),%dl
mov    -0x22(%rbp),%cl
mov    -0x23(%rbp),%al
lea    0xe17(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
movzbl -0x24(%rbp),%r9d
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateRandomIPAddress>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1060 <init_rand@plt>
xor    %eax,%eax
call   1050 <rand_cmwc@plt>
mov    %eax,%ecx
shr    $0x18,%ecx
cmp    $0x1000000,%eax
adc    $0x0,%cl
cmp    $0x1,%al
mov    %eax,%ebx
adc    $0x0,%bl
mov    %eax,%esi
shr    $0x10,%esi
movzbl %cl,%edx
movzbl %bl,%r9d
movzbl %ah,%eax
movzbl %sil,%ecx
lea    0xe63(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%r8d
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define void @generateRandomIPAddress(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %2
%9 = call i32 @time(i32* null)
%10 = call i32 @init_rand(i32 %9)
%11 = call i32 (...) @rand_cmwc()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = and i32 %12, -16777216
%14 = lshr i32 %13, 24
%15 = trunc i32 %14 to i8
store i8 %15, i8* %5
%16 = load i32, i32* %3
%17 = and i32 %16, 16711680
%18 = ashr i32 %17, 16
%19 = trunc i32 %18 to i8
store i8 %19, i8* %6
%20 = load i32, i32* %3
%21 = and i32 %20, 65280
%22 = ashr i32 %21, 8
%23 = trunc i32 %22 to i8
store i8 %23, i8* %7
%24 = load i32, i32* %3
%25 = and i32 %24, 255
%26 = trunc i32 %25 to i8
store i8 %26, i8* %8
%27 = load i8, i8* %5
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %1
%31 = load i8, i8* %5
%32 = add i8 %31, 1
store i8 %32, i8* %5
br label %33
33: ; preds = %30, %1
%34 = load i8, i8* %8
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %8
%39 = add i8 %38, 1
store i8 %39, i8* %8
br label %40
40: ; preds = %37, %33
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%42 = load i8, i8* %5
%43 = load i8, i8* %6
%44 = load i8, i8* %7
%45 = load i8, i8* %8
%46 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %42, i8 zeroext %43, i8 zeroext %44, i8 zeroext %45)
%47 = load i8*, i8** %2
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%49 = call i32 @strcpy(i8* %47, i8* %48)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define void @generateRandomIPAddress(i8* %0) {
%2 = alloca [16 x i8]
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @init_rand(i32 %3)
%5 = tail call i32 (...) @rand_cmwc()
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = lshr i32 %5, 24
%8 = trunc i32 %7 to i8
%9 = trunc i32 %5 to i8
%10 = icmp ult i32 %5, 16777216
%11 = zext i1 %10 to i8
%12 = add i8 %8, %11
%13 = and i32 %5, 255
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i8
%16 = add i8 %15, %9
%17 = lshr i32 %5, 8
%18 = trunc i32 %17 to i8
%19 = lshr i32 %5, 16
%20 = trunc i32 %19 to i8
%21 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i8 zeroext %20, i8 zeroext %18, i8 zeroext %16)
%22 = call i32 @strcpy(i8* %0, i8* %6)
ret void
}