#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__ random();
int /*<<< orphan*/ sprintf(char *, char *, char const *, int, ...);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *class2ip(const char *class) {
  static char ip[16];
  int i, j;
  for (i = 0, j = 0; class[i] != '\0'; ++i)
    if (class[i] == '.')
      ++j;
  switch (j) {
  case 0:
    sprintf(ip, "%s.%d.%d.%d", class, (int)random() % 255 + 1,
            (int)random() % 255 + 1, (int)random() % 255 + 1);
    break;
  case 1:
    sprintf(ip, "%s.%d.%d", class, (int)random() % 255 + 1,
            (int)random() % 255 + 1);
    break;
  case 2:
    sprintf(ip, "%s.%d", class, (int)random() % 255 + 1);
    break;
  default:
    strncpy(ip, class, 16);
    break;
  }
  return ip;
}


x86 assembly (clang, -O0):
<class2ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1190 <class2ip+0x60>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    117d <class2ip+0x4d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1182 <class2ip+0x52>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <class2ip+0x1a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11c5 <class2ip+0x95>
jmp    11a3 <class2ip+0x73>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1232 <class2ip+0x102>
jmp    11b4 <class2ip+0x84>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1286 <class2ip+0x156>
jmp    12c0 <class2ip+0x190>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    $0xff,%esi
cltd
idiv   %esi
mov    %edx,%r9d
mov    -0x20(%rbp),%rdx
add    $0x1,%r9d
lea    0x2e31(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12d5 <class2ip+0x1a5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    -0x34(%rbp),%ecx
mov    $0xff,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    -0x30(%rbp),%rdx
add    $0x1,%r8d
lea    0x2ddd(%rip),%rdi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12d5 <class2ip+0x1a5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x40(%rbp),%rdx
add    $0x1,%ecx
lea    0x2da3(%rip),%rdi
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12d5 <class2ip+0x1a5>
mov    -0x8(%rbp),%rsi
lea    0x2d85(%rip),%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0x2d74(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<class2ip>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
mov    %rdi,%rcx
jmp    1147 <class2ip+0x17>
xchg   %ax,%ax
add    $0x1,%eax
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x2e,%dl
je     1140 <class2ip+0x10>
test   %dl,%dl
jne    1143 <class2ip+0x13>
cmp    $0x2,%eax
je     121b <class2ip+0xeb>
cmp    $0x1,%eax
je     1264 <class2ip+0x134>
test   %eax,%eax
jne    12dc <class2ip+0x1ac>
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%r14d
add    $0x1,%r14d
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%r9d
add    $0x1,%r9d
lea    0x2e51(%rip),%rdi
lea    0xdfa(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    12f0 <class2ip+0x1c0>
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
add    %eax,%ecx
add    $0x1,%ecx
lea    0x2e02(%rip),%rdi
lea    0xdc0(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    12f0 <class2ip+0x1c0>
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%r8d
add    $0x1,%r8d
lea    0x2d89(%rip),%rdi
lea    0xd3e(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    12f0 <class2ip+0x1c0>
lea    0x2d6d(%rip),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0x2d59(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@class2ip.ip = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%s.%d.%d.%d\00"
@.str.1 = [9 x i8] c"%s.%d.%d\00"
@.str.2 = [6 x i8] c"%s.%d\00"
define i8* @class2ip(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %25, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %24
24: ; preds = %21, %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %5
28: ; preds = %5
%29 = load i32, i32* %4
switch i32 %29, label %63 [
i32 0, label %30
i32 1, label %45
i32 2, label %56
]
30: ; preds = %28
%31 = load i8*, i8** %2
%32 = call i64 (...) @random()
%33 = trunc i64 %32 to i32
%34 = srem i32 %33, 255
%35 = add nsw i32 %34, 1
%36 = call i64 (...) @random()
%37 = trunc i64 %36 to i32
%38 = srem i32 %37, 255
%39 = add nsw i32 %38, 1
%40 = call i64 (...) @random()
%41 = trunc i64 %40 to i32
%42 = srem i32 %41, 255
%43 = add nsw i32 %42, 1
%44 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %31, i32 %35, i32 %39, i32 %43)
br label %66
45: ; preds = %28
%46 = load i8*, i8** %2
%47 = call i64 (...) @random()
%48 = trunc i64 %47 to i32
%49 = srem i32 %48, 255
%50 = add nsw i32 %49, 1
%51 = call i64 (...) @random()
%52 = trunc i64 %51 to i32
%53 = srem i32 %52, 255
%54 = add nsw i32 %53, 1
%55 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %46, i32 %50, i32 %54)
br label %66
56: ; preds = %28
%57 = load i8*, i8** %2
%58 = call i64 (...) @random()
%59 = trunc i64 %58 to i32
%60 = srem i32 %59, 255
%61 = add nsw i32 %60, 1
%62 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %57, i32 %61)
br label %66
63: ; preds = %28
%64 = load i8*, i8** %2
%65 = call i32 @strncpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* %64, i32 16)
br label %66
66: ; preds = %63, %56, %45, %30
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0)
}

LLVM IR (-O2):
@class2ip.ip = internal global [16 x i8] zeroinitializer
@.str = [12 x i8] c"%s.%d.%d.%d\00"
@.str.1 = [9 x i8] c"%s.%d.%d\00"
@.str.2 = [6 x i8] c"%s.%d\00"
define i8* @class2ip(i8* %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i64 [ %11, %9 ], [ 0, %1 ]
%4 = phi i32 [ %10, %9 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 0, label %12
i8 46, label %7
]
7: ; preds = %2
%8 = add nsw i32 %4, 1
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ %4, %2 ]
%11 = add nuw i64 %3, 1
br label %2
12: ; preds = %2
switch i32 %4, label %43 [
i32 0, label %13
i32 1, label %27
i32 2, label %37
]
13: ; preds = %12
%14 = tail call i64 (...) @random()
%15 = trunc i64 %14 to i32
%16 = srem i32 %15, 255
%17 = add nsw i32 %16, 1
%18 = tail call i64 (...) @random()
%19 = trunc i64 %18 to i32
%20 = srem i32 %19, 255
%21 = add nsw i32 %20, 1
%22 = tail call i64 (...) @random()
%23 = trunc i64 %22 to i32
%24 = srem i32 %23, 255
%25 = add nsw i32 %24, 1
%26 = tail call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %17, i32 %21, i32 %25)
br label %45
27: ; preds = %12
%28 = tail call i64 (...) @random()
%29 = trunc i64 %28 to i32
%30 = srem i32 %29, 255
%31 = add nsw i32 %30, 1
%32 = tail call i64 (...) @random()
%33 = trunc i64 %32 to i32
%34 = srem i32 %33, 255
%35 = add nsw i32 %34, 1
%36 = tail call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %31, i32 %35)
br label %45
37: ; preds = %12
%38 = tail call i64 (...) @random()
%39 = trunc i64 %38 to i32
%40 = srem i32 %39, 255
%41 = add nsw i32 %40, 1
%42 = tail call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %41)
br label %45
43: ; preds = %12
%44 = tail call i32 @strncpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0), i8* %0, i32 16)
br label %45
45: ; preds = %43, %37, %27, %13
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @class2ip.ip, i64 0, i64 0)
}