#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 */
struct in_addr {
  char *s_addr;
};

/* Variables and functions */
long inet_addr(char *);
long inet_aton(char *, struct in_addr *);
long inet_network(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(struct in_addr *, long *, int);
char *ntohl(long);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char ip[] = "192.168.0.74";
  long r1, r2, r3;
  struct in_addr addr;
  r1 = inet_addr(ip);
  if (-1 == r1) {
    printf("inet_addr return -1\n");
  } else {
    printf("inet_addr ip: %ld\n", r1);
  }
  r2 = inet_network(ip);
  if (-1 == r2) {
    printf("inet_addr return -1\n");
  } else {
    printf("inet_network ip: %ld\n", r2);
    printf("inet_network ip: %ld\n", ntohl(r2));
  }
  r3 = inet_aton(ip, &addr);
  if (0 == r3) {
    printf("inet_aton return -1\n");
  } else {
    printf("inet_aton ip: %ld\n", addr.s_addr);
  }
  struct in_addr addr1, addr2;
  long l1, l2;
  l1 = inet_addr("192.168.0.74");
  l2 = inet_addr("211.100.21.179");
  printf("l1 is %ld\n", l1);
  printf("l2 is %ld\n", l2);
  memcpy(&addr1, &l1, 4);
  memcpy(&addr2, &l2, 4);
  printf("%s : %s\n", inet_ntoa(addr1), inet_ntoa(addr2));
  printf("%s\n", inet_ntoa(addr1));
  printf("%s\n", inet_ntoa(addr2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xe78(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xe73(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0x11(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x20(%rbp),%rax
jne    11cd <main+0x5d>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11df <main+0x6f>
mov    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x11(%rbp),%rdi
call   1030 <inet_network@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x28(%rbp),%rax
jne    1210 <main+0xa0>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123c <main+0xcc>
mov    -0x28(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <ntohl@plt>
mov    %rax,%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x11(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1080 <inet_aton@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    126c <main+0xfc>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127e <main+0x10e>
mov    -0x38(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd7b(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %rax,-0x50(%rbp)
lea    0xdde(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    -0x48(%rbp),%rdi
lea    -0x58(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x40(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movabs $0x34372e302e3836,%rax
mov    %rax,0x5(%rsp)
movabs $0x2e3836312e323931,%rax
36 38 2e
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1070 <inet_addr@plt>
cmp    $0xffffffffffffffff,%rax
je     11c5 <main+0x45>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11d1 <main+0x51>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <inet_network@plt>
cmp    $0xffffffffffffffff,%rax
je     120d <main+0x8d>
mov    %rax,%rbx
lea    0xe2a(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10a0 <ntohl@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1219 <main+0x99>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
lea    0x30(%rsp),%rsi
call   1090 <inet_aton@plt>
test   %rax,%rax
je     1240 <main+0xc0>
mov    0x30(%rsp),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    124c <main+0xcc>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xde9(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %rax,%rbx
mov    %rax,0x28(%rsp)
lea    0xde2(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %rax,%r14
mov    %rax,0x20(%rsp)
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x18(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    0x18(%rsp),%rdi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rdi
call   1050 <inet_ntoa@plt>
lea    0xd92(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rsp),%rdi
call   1050 <inet_ntoa@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdi
call   1050 <inet_ntoa@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.in_addr = type { i8* }
@__const.main.ip = [13 x i8] c"192.168.0.74\00"
@.str = [21 x i8] c"inet_addr return -1\0A\00"
@.str.1 = [19 x i8] c"inet_addr ip: %ld\0A\00"
@.str.2 = [22 x i8] c"inet_network ip: %ld\0A\00"
@.str.3 = [21 x i8] c"inet_aton return -1\0A\00"
@.str.4 = [19 x i8] c"inet_aton ip: %ld\0A\00"
@.str.5 = [13 x i8] c"192.168.0.74\00"
@.str.6 = [15 x i8] c"211.100.21.179\00"
@.str.7 = [11 x i8] c"l1 is %ld\0A\00"
@.str.8 = [11 x i8] c"l2 is %ld\0A\00"
@.str.9 = [9 x i8] c"%s : %s\0A\00"
@.str.10 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [13 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.in_addr
%7 = alloca %struct.in_addr
%8 = alloca %struct.in_addr
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %1
%11 = bitcast [13 x i8]* %2 to i8*
%12 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%13 = call i64 @inet_addr(i8* %12)
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = icmp eq i64 -1, %14
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %21
18: ; preds = %0
%19 = load i64, i64* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %19)
br label %21
21: ; preds = %18, %16
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%23 = call i64 @inet_network(i8* %22)
store i64 %23, i64* %4
%24 = load i64, i64* %4
%25 = icmp eq i64 -1, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %34
28: ; preds = %21
%29 = load i64, i64* %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = load i64, i64* %4
%32 = call i8* @ntohl(i64 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %28, %26
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%36 = call i64 @inet_aton(i8* %35, %struct.in_addr* %6)
store i64 %36, i64* %5
%37 = load i64, i64* %5
%38 = icmp eq i64 0, %37
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %45
41: ; preds = %34
%42 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %41, %39
%46 = call i64 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i64 %46, i64* %9
%47 = call i64 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i64 %47, i64* %10
%48 = load i64, i64* %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i64 %48)
%50 = load i64, i64* %10
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %50)
%52 = call i32 @memcpy(%struct.in_addr* %7, i64* %9, i32 4)
%53 = call i32 @memcpy(%struct.in_addr* %8, i64* %10, i32 4)
%54 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i8* @inet_ntoa(i8* %55)
%57 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i8* @inet_ntoa(i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %56, i8* %59)
%61 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = call i8* @inet_ntoa(i8* %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = call i8* @inet_ntoa(i8* %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %67)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i8* }
@.str.1 = [19 x i8] c"inet_addr ip: %ld\0A\00"
@.str.2 = [22 x i8] c"inet_network ip: %ld\0A\00"
@.str.4 = [19 x i8] c"inet_aton ip: %ld\0A\00"
@.str.5 = [13 x i8] c"192.168.0.74\00"
@.str.6 = [15 x i8] c"211.100.21.179\00"
@.str.7 = [11 x i8] c"l1 is %ld\0A\00"
@.str.8 = [11 x i8] c"l2 is %ld\0A\00"
@.str.9 = [9 x i8] c"%s : %s\0A\00"
@str = [20 x i8] c"inet_aton return -1\00"
@str.12 = [20 x i8] c"inet_addr return -1\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = alloca %struct.in_addr
%3 = alloca %struct.in_addr
%4 = alloca %struct.in_addr
%5 = alloca i64
%6 = alloca i64
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%8 = bitcast %struct.in_addr* %2 to i8*
%9 = call i64 @inet_addr(i8* %7)
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %9)
br label %15
15: ; preds = %13, %11
%16 = call i64 @inet_network(i8* %7)
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
br label %24
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%22 = call i8* @ntohl(i64 %16)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %18
%25 = call i64 @inet_aton(i8* %7, %struct.in_addr* %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %33
29: ; preds = %24
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29, %27
%34 = bitcast %struct.in_addr* %3 to i8*
%35 = bitcast %struct.in_addr* %4 to i8*
%36 = bitcast i64* %5 to i8*
%37 = bitcast i64* %6 to i8*
%38 = call i64 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i64 %38, i64* %5
%39 = call i64 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i64 %39, i64* %6
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i64 %38)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %39)
%42 = call i32 @memcpy(%struct.in_addr* %3, i64* %5, i32 4)
%43 = call i32 @memcpy(%struct.in_addr* %4, i64* %6, i32 4)
%44 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%45 = load i8*, i8** %44
%46 = call i8* @inet_ntoa(i8* %45)
%47 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%48 = load i8*, i8** %47
%49 = call i8* @inet_ntoa(i8* %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %46, i8* %49)
%51 = load i8*, i8** %44
%52 = call i8* @inet_ntoa(i8* %51)
%53 = call i32 @puts(i8* dereferenceable(1) %52)
%54 = load i8*, i8** %47
%55 = call i8* @inet_ntoa(i8* %54)
%56 = call i32 @puts(i8* dereferenceable(1) %55)
ret i32 0
}