#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 htonl(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int main(int argc, char **argv) {
  unsigned int octet = 0, ip_addr = 0;
  char *str_ip, str[256];
  str_ip = str;
  printf("Please provide IPV4 address in string format \n");
  scanf("%s", str_ip);
  printf("\nIP address: %s\n", str_ip);
  while (*str_ip) {
    octet = octet * 10 + (*str_ip - '0');
    ((void)0);
    str_ip++;
    if ((*str_ip == '.') || (*str_ip == 0)) {
      ((void)0);
      ip_addr = (ip_addr << 8) | octet;
      ((void)0);
      octet = 0x0;
      if (*str_ip)
        str_ip++;
    }
  }
  printf("\nIP Address Hex: 0x%x, network order 0x%x\n\n", ip_addr,
         htonl(ip_addr));
  char re_str[256];
  if (ip_addr == 0x0)
    str_ip = "0.0.0.0";
  else {
    str_ip = re_str;
    str_ip += snprintf(str_ip, 5, "%d.", (ip_addr >> 24) & 0x000000FF);
    ((void)0);
    str_ip += snprintf(str_ip, 5, "%d.", (ip_addr >> 16) & 0x000000FF);
    ((void)0);
    str_ip += snprintf(str_ip, 5, "%d.", (ip_addr >> 8) & 0x000000FF);
    ((void)0);
    str_ip += snprintf(str_ip, 5, "%d", ip_addr & 0x000000FF);
    printf("IP Address Re-Str %s\n", re_str);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1224 <main+0xe4>
imul   $0xa,-0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11ee <main+0xae>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    121f <main+0xdf>
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     121a <main+0xda>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    121f <main+0xdf>
jmp    11a2 <main+0x62>
mov    -0x18(%rbp),%eax
mov    %eax,-0x224(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htonl@plt>
mov    -0x224(%rbp),%esi
mov    %eax,%edx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1265 <main+0x125>
lea    0xe13(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1346 <main+0x206>
lea    -0x220(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%ecx
shr    $0x18,%ecx
and    $0xff,%ecx
mov    $0x5,%esi
lea    0xdeb(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%ecx
shr    $0x10,%ecx
and    $0xff,%ecx
mov    $0x5,%esi
lea    0xdba(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%ecx
shr    $0x8,%ecx
and    $0xff,%ecx
mov    $0x5,%esi
lea    0xd89(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
mov    $0x5,%esi
lea    0xd5f(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    -0x220(%rbp),%rsi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8e(%rip),%rdi
lea    0x100(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe7a(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x100(%rsp),%cl
test   %cl,%cl
je     11f9 <main+0xa9>
xor    %ebp,%ebp
xor    %eax,%eax
jmp    11c8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
mov    %edi,%ebp
or     %eax,%ebp
mov    %cl,%sil
neg    %rsi
movzbl 0x2(%rbx,%rsi,1),%ecx
xor    %eax,%eax
mov    %rdx,%rbx
test   %cl,%cl
je     11f9 <main+0xa9>
lea    (%rax,%rax,4),%eax
movsbl %cl,%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
lea    0x1(%rbx),%rdx
movzbl 0x1(%rbx),%ecx
cmp    $0x2e,%cl
je     11e5 <main+0x95>
test   %cl,%cl
jne    11c1 <main+0x71>
shl    $0x8,%ebp
mov    %ebp,%edi
xor    %esi,%esi
test   %cl,%cl
sete   %cl
je     11b0 <main+0x60>
lea    0x2(%rbx),%rdx
jmp    11b0 <main+0x60>
mov    %ebp,%ebx
mov    %ebp,%edi
call   1060 <htonl@plt>
lea    0xe0b(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
je     12a2 <main+0x152>
mov    %ebx,%ecx
shr    $0x18,%ecx
lea    0xe18(%rip),%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
call   1050 <snprintf@plt>
cltq
lea    (%rsp,%rax,1),%r12
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%ecx
mov    %r12,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
call   1050 <snprintf@plt>
mov    %ebx,%edx
movslq %eax,%rbx
add    %r12,%rbx
movzbl %dh,%ecx
mov    %edx,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
call   1050 <snprintf@plt>
movslq %eax,%rdi
add    %rbx,%rdi
movzbl %bpl,%ecx
lea    0xdbd(%rip),%rdx
mov    $0x5,%esi
call   1050 <snprintf@plt>
lea    0xdaf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Please provide IPV4 address in string format \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"\0AIP address: %s\0A\00"
@.str.3 = [44 x i8] c"\0AIP Address Hex: 0x%x, network order 0x%x\0A\0A\00"
@.str.4 = [8 x i8] c"0.0.0.0\00"
@.str.5 = [4 x i8] c"%d.\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [22 x i8] c"IP Address Re-Str %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8* %11, i8** %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %8
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %52, %2
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = load i32, i32* %6
%23 = mul i32 %22, 10
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
%28 = add i32 %23, %27
store i32 %28, i32* %6
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 46
br i1 %34, label %40, label %35
35: ; preds = %21
%36 = load i8*, i8** %8
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %35, %21
%41 = load i32, i32* %7
%42 = shl i32 %41, 8
%43 = load i32, i32* %6
%44 = or i32 %42, %43
store i32 %44, i32* %7
store i32 0, i32* %6
%45 = load i8*, i8** %8
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %8
br label %51
51: ; preds = %48, %40
br label %52
52: ; preds = %51, %35
br label %17
53: ; preds = %17
%54 = load i32, i32* %7
%55 = load i32, i32* %7
%56 = call i32 @htonl(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %56)
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %53
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %8
br label %96
61: ; preds = %53
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %62, i8** %8
%63 = load i8*, i8** %8
%64 = load i32, i32* %7
%65 = lshr i32 %64, 24
%66 = and i32 %65, 255
%67 = call i32 @snprintf(i8* %63, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load i8*, i8** %8
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %68, i64 %69
store i8* %70, i8** %8
%71 = load i8*, i8** %8
%72 = load i32, i32* %7
%73 = lshr i32 %72, 16
%74 = and i32 %73, 255
%75 = call i32 @snprintf(i8* %71, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %74)
%76 = load i8*, i8** %8
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds i8, i8* %76, i64 %77
store i8* %78, i8** %8
%79 = load i8*, i8** %8
%80 = load i32, i32* %7
%81 = lshr i32 %80, 8
%82 = and i32 %81, 255
%83 = call i32 @snprintf(i8* %79, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %82)
%84 = load i8*, i8** %8
%85 = sext i32 %83 to i64
%86 = getelementptr inbounds i8, i8* %84, i64 %85
store i8* %86, i8** %8
%87 = load i8*, i8** %8
%88 = load i32, i32* %7
%89 = and i32 %88, 255
%90 = call i32 @snprintf(i8* %87, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %89)
%91 = load i8*, i8** %8
%92 = sext i32 %90 to i64
%93 = getelementptr inbounds i8, i8* %91, i64 %92
store i8* %93, i8** %8
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %61, %60
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"\0AIP address: %s\0A\00"
@.str.3 = [44 x i8] c"\0AIP Address Hex: 0x%x, network order 0x%x\0A\0A\00"
@.str.5 = [4 x i8] c"%d.\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [22 x i8] c"IP Address Re-Str %s\0A\00"
@str = [46 x i8] c"Please provide IPV4 address in string format \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 0
br i1 %10, label %35, label %11
11: ; preds = %2, %29
%12 = phi i8 [ %30, %29 ], [ %9, %2 ]
%13 = phi i8* [ %33, %29 ], [ %5, %2 ]
%14 = phi i32 [ %32, %29 ], [ 0, %2 ]
%15 = phi i32 [ %31, %29 ], [ 0, %2 ]
%16 = mul i32 %15, 10
%17 = sext i8 %12 to i32
%18 = add i32 %16, -48
%19 = add i32 %18, %17
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = load i8, i8* %20
switch i8 %21, label %29 [
i8 46, label %22
i8 0, label %22
]
22: ; preds = %11, %11
%23 = shl i32 %14, 8
%24 = or i32 %19, %23
%25 = icmp eq i8 %21, 0
%26 = getelementptr inbounds i8, i8* %13, i64 2
%27 = select i1 %25, i8* %20, i8* %26
%28 = load i8, i8* %27
br label %29
29: ; preds = %22, %11
%30 = phi i8 [ %21, %11 ], [ %28, %22 ]
%31 = phi i32 [ %19, %11 ], [ 0, %22 ]
%32 = phi i32 [ %14, %11 ], [ %24, %22 ]
%33 = phi i8* [ %20, %11 ], [ %27, %22 ]
%34 = icmp eq i8 %30, 0
br i1 %34, label %35, label %11
35: ; preds = %29, %2
%36 = phi i32 [ 0, %2 ], [ %32, %29 ]
%37 = call i32 @htonl(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%40 = icmp eq i32 %36, 0
br i1 %40, label %59, label %41
41: ; preds = %35
%42 = lshr i32 %36, 24
%43 = call i32 @snprintf(i8* %39, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %44
%46 = lshr i32 %36, 16
%47 = and i32 %46, 255
%48 = call i32 @snprintf(i8* %45, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %45, i64 %49
%51 = lshr i32 %36, 8
%52 = and i32 %51, 255
%53 = call i32 @snprintf(i8* %50, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = and i32 %36, 255
%57 = call i32 @snprintf(i8* %55, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %39)
br label %59
59: ; preds = %35, %41
ret i32 0
}