#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 slist {
  int dummy;
};
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int htonl(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ slist_find(struct slist *, char const *, int, int /*<<< orphan*/ *);
void find_valid_range(struct slist *slist, int range) {
  int i;
  for (i = 0; i < range; ++i) {
    int n = htonl(i);
    assert(slist_find(slist, (const char *)&n, sizeof(n), NULL) == 0);
    printf("find_valid_range=%d\n", i);
  }
}


x86 assembly (clang, -O0):
<find_valid_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <find_valid_range+0x71>
mov    -0x10(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <slist_find@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <find_valid_range+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_valid_range>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11ac <find_valid_range+0x6c>
mov    %esi,%ebp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
lea    0xe9d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <slist_find@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1170 <find_valid_range+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.slist = type { i32 }
@.str = [21 x i8] c"find_valid_range=%d\0A\00"
define void @find_valid_range(%struct.slist* %0, i32 %1) {
%3 = alloca %struct.slist*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.slist* %0, %struct.slist** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i32, i32* %5
%13 = call i32 @htonl(i32 %12)
store i32 %13, i32* %6
%14 = load %struct.slist*, %struct.slist** %3
%15 = bitcast i32* %6 to i8*
%16 = call i64 @slist_find(%struct.slist* %14, i8* %15, i32 4, i32* null)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %11
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.slist = type { i32 }
@.str = [21 x i8] c"find_valid_range=%d\0A\00"
define void @find_valid_range(%struct.slist* %0, i32 %1) {
%3 = alloca i32
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ 0, %5 ], [ %15, %7 ]
%9 = call i32 @htonl(i32 %8)
store i32 %9, i32* %3
%10 = call i64 @slist_find(%struct.slist* %0, i8* %6, i32 4, i32* null)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %8)
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %7
17: ; preds = %7, %2
ret void
}