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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ shash_find(struct shash *, char *, size_t, int /*<<< orphan*/ *);
size_t snprintf(char *, int, char *, int);
void find_range(struct shash *shash, int range) {
  char buffer[32];
  int i;
  for (i = 0; i < range; ++i) {
    size_t len = snprintf(buffer, sizeof(buffer), "%d", i);
    if (len >= sizeof(buffer))
      len = sizeof(buffer) - 1;
    assert(0 == shash_find(shash, buffer, len + 1, NULL));
  }
}


x86 assembly (clang, -O0):
<find_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bd <find_range+0x8d>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%ecx
mov    $0x20,%esi
lea    0xe9b(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x20,-0x40(%rbp)
jb     1181 <find_range+0x51>
movq   $0x1f,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
add    $0x1,%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <shash_find@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <find_range+0x16>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
jle    11a1 <find_range+0x71>
mov    %esi,%r12d
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xeaf(%rip),%r15
mov    %rsp,%rbp
mov    $0x1f,%r13d
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1040 <snprintf@plt>
cmp    $0x1f,%rax
cmovae %r13,%rax
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1030 <shash_find@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1160 <find_range+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.shash = type { i32 }
@.str = [3 x i8] c"%d\00"
define void @find_range(%struct.shash* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %2, %6
%7 = phi i32 [ %16, %6 ], [ 0, %2 ]
%8 = call i64 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ult i64 %8, 31
%10 = select i1 %9, i64 %8, i64 31
%11 = add nuw nsw i64 %10, 1
%12 = call i64 @shash_find(%struct.shash* %0, i8* %4, i64 %11, i32* null)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %6
18: ; preds = %6, %2
ret void
}