#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 {
  int s_addr;
};

/* Variables and functions */
int htonl(scalar_t__);
char *inet_ntoa(struct in_addr);
scalar_t__ ntohl(int);
int /*<<< orphan*/ printf(char *, char *);
int scan_ip(struct in_addr ip, struct in_addr mask) {
  struct in_addr broadcast, reseau, currentIP;
  reseau.s_addr = ip.s_addr & mask.s_addr;
  broadcast.s_addr = reseau.s_addr | ~mask.s_addr;
  for (currentIP = reseau; currentIP.s_addr < broadcast.s_addr;
       currentIP.s_addr = htonl(ntohl(currentIP.s_addr) + 1)) {
    printf("IPv4 %s\n", inet_ntoa(currentIP));
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
xor    $0xffffffff,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11aa <scan_ip+0x6a>
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
call   1060 <ntohl@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <htonl@plt>
mov    %eax,-0x28(%rbp)
jmp    116b <scan_ip+0x2b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_ip>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %esi,%ebp
and    %edi,%ebp
not    %ebx
or     %edi,%ebx
cmp    %ebx,%ebp
jge    1188 <scan_ip+0x48>
lea    0xea7(%rip),%r14
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <ntohl@plt>
lea    0x1(%rax),%rdi
call   1050 <htonl@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
jl     1160 <scan_ip+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [9 x i8] c"IPv4 %s\0A\00"
define i32 @scan_ip(i32 %0, i32 %1) {
%3 = alloca %struct.in_addr
%4 = alloca %struct.in_addr
%5 = alloca %struct.in_addr
%6 = alloca %struct.in_addr
%7 = alloca %struct.in_addr
%8 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %0, i32* %8
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %1, i32* %9
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %11, %13
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = xor i32 %19, -1
%21 = or i32 %17, %20
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.in_addr* %7 to i8*
%24 = bitcast %struct.in_addr* %6 to i8*
br label %25
25: ; preds = %36, %2
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%29 = load i32, i32* %28
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %43
31: ; preds = %25
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i8* @inet_ntoa(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %31
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @ntohl(i32 %38)
%40 = add nsw i64 %39, 1
%41 = call i32 @htonl(i64 %40)
%42 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i32 %41, i32* %42
br label %25
43: ; preds = %25
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"IPv4 %s\0A\00"
define i32 @scan_ip(i32 %0, i32 %1) {
%3 = and i32 %1, %0
%4 = xor i32 %1, -1
%5 = or i32 %4, %0
%6 = icmp slt i32 %3, %5
br i1 %6, label %7, label %15
7: ; preds = %2, %7
%8 = phi i32 [ %13, %7 ], [ %3, %2 ]
%9 = tail call i8* @inet_ntoa(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i64 @ntohl(i32 %8)
%12 = add nsw i64 %11, 1
%13 = tail call i32 @htonl(i64 %12)
%14 = icmp slt i32 %13, %5
br i1 %14, label %7, label %15
15: ; preds = %7, %2
ret i32 0
}