#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 */
scalar_t__ malloc(int);
int rand();
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *ipv4() {
  srand(time(NULL));
  char *ip = (char *)malloc(18);
  snprintf(&ip[0], 18, "%d.%d.%d.%d", (rand() % 256), (rand() % 256),
           (rand() % 256), (rand() % 256));
  return (ip);
}


x86 assembly (clang, -O0):
<ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x12,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    $0x100,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    $0x12,%esi
lea    0xe20(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x12,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r15d
lea    0xff(%r15),%eax
test   %r15d,%r15d
cmovns %r15d,%eax
and    $0xffffff00,%eax
sub    %eax,%r15d
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r12d
lea    0xff(%r12),%eax
test   %r12d,%r12d
cmovns %r12d,%eax
and    $0xffffff00,%eax
sub    %eax,%r12d
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebx
lea    0xff(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffff00,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1070 <rand@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp)
lea    0xe0d(%rip),%rdx
mov    %r14,%rdi
mov    $0x12,%esi
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebx,%r9d
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ipv4() {
%1 = alloca i8*
%2 = call i32 @time(i32* null)
%3 = call i32 @srand(i32 %2)
%4 = call i64 @malloc(i32 18)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 256
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 256
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 256
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 256
%16 = call i32 @snprintf(i8* %7, i32 18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %15)
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @ipv4() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i64 @malloc(i32 18)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 256
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 256
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 256
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 256
%13 = tail call i32 @snprintf(i8* %4, i32 18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32 %12)
ret i8* %4
}