#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int INT_MAX;
int INT_MIN;
int UINT_MAX;
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int /*<<< orphan*/ test_lookup_fail(int, char *);
void test_lookup(int fd) {
  char buf[64];
  unsigned int u;
  int i;
  for (i = INT_MIN; i < INT_MIN + 1024; i++) {
    snprintf(buf, sizeof(buf), "%d", i);
    test_lookup_fail(fd, buf);
  }
  for (i = -1024; i < 1024; i++) {
    snprintf(buf, sizeof(buf), "%d", i);
    test_lookup_fail(fd, buf);
  }
  for (u = INT_MAX - 1024; u < (unsigned int)INT_MAX + 1024; u++) {
    snprintf(buf, sizeof(buf), "%u", u);
    test_lookup_fail(fd, buf);
  }
  for (u = UINT_MAX - 1024; u != 0; u++) {
    snprintf(buf, sizeof(buf), "%u", u);
    test_lookup_fail(fd, buf);
  }
}


x86 assembly (clang, -O0):
<test_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%ecx
add    $0x400,%ecx
cmp    %ecx,%eax
jge    1183 <test_lookup+0x63>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%ecx
mov    $0x40,%esi
lea    0xe9c(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <test_lookup_fail@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1137 <test_lookup+0x17>
movl   $0xfffffc00,-0x58(%rbp)
cmpl   $0x400,-0x58(%rbp)
jge    11c9 <test_lookup+0xa9>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%ecx
mov    $0x40,%esi
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <test_lookup_fail@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    118a <test_lookup+0x6a>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
sub    $0x400,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2e04(%rip),%rcx
mov    (%rcx),%ecx
add    $0x400,%ecx
cmp    %ecx,%eax
jae    1226 <test_lookup+0x106>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    $0x40,%esi
lea    0xdfc(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <test_lookup_fail@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11da <test_lookup+0xba>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
sub    $0x400,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1273 <test_lookup+0x153>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    $0x40,%esi
lea    0xdaf(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <test_lookup_fail@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1237 <test_lookup+0x117>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_lookup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edi,%r12d
mov    0x2ea0(%rip),%r13
mov    0x0(%r13),%ebp
lea    0xebd(%rip),%r14
mov    %rsp,%r15
mov    $0x3ff,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %r12d,%edi
mov    %r15,%rsi
call   1040 <test_lookup_fail@plt>
lea    0x1(%rbp),%eax
mov    0x0(%r13),%ecx
add    %ebx,%ecx
cmp    %ecx,%ebp
mov    %eax,%ebp
jl     1150 <test_lookup+0x30>
mov    $0xfffffc00,%ebp
lea    0xe78(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <test_lookup_fail@plt>
add    $0x1,%ebp
cmp    $0x400,%ebp
jne    1190 <test_lookup+0x70>
mov    0x2e29(%rip),%r13
mov    0x0(%r13),%eax
lea    -0x400(%rax),%ebp
add    $0x400,%eax
cmp    %eax,%ebp
jae    121a <test_lookup+0xfa>
lea    0xe2a(%rip),%r14
mov    %rsp,%r15
mov    $0x400,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %r12d,%edi
mov    %r15,%rsi
call   1040 <test_lookup_fail@plt>
add    $0x1,%ebp
mov    0x0(%r13),%eax
add    %ebx,%eax
cmp    %eax,%ebp
jb     11f0 <test_lookup+0xd0>
mov    0x2dbf(%rip),%rax
mov    $0xfffffc00,%ebp
add    (%rax),%ebp
je     1261 <test_lookup+0x141>
lea    0xdd2(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <test_lookup_fail@plt>
inc    %ebp
jne    1240 <test_lookup+0x120>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MIN = global i32 0
@.str = [3 x i8] c"%d\00"
@INT_MAX = global i32 0
@.str.1 = [3 x i8] c"%u\00"
@UINT_MAX = global i32 0
define void @test_lookup(i32 %0) {
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @INT_MIN
store i32 %6, i32* %5
br label %7
7: ; preds = %19, %1
%8 = load i32, i32* %5
%9 = load i32, i32* @INT_MIN
%10 = add nsw i32 %9, 1024
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %5
%15 = call i32 @snprintf(i8* %13, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%18 = call i32 @test_lookup_fail(i32 %16, i8* %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
store i32 -1024, i32* %5
br label %23
23: ; preds = %33, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 1024
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @snprintf(i8* %27, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%32 = call i32 @test_lookup_fail(i32 %30, i8* %31)
br label %33
33: ; preds = %26
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %23
36: ; preds = %23
%37 = load i32, i32* @INT_MAX
%38 = sub nsw i32 %37, 1024
store i32 %38, i32* %4
br label %39
39: ; preds = %51, %36
%40 = load i32, i32* %4
%41 = load i32, i32* @INT_MAX
%42 = add i32 %41, 1024
%43 = icmp ult i32 %40, %42
br i1 %43, label %44, label %54
44: ; preds = %39
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%46 = load i32, i32* %4
%47 = call i32 @snprintf(i8* %45, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %2
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%50 = call i32 @test_lookup_fail(i32 %48, i8* %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %4
%53 = add i32 %52, 1
store i32 %53, i32* %4
br label %39
54: ; preds = %39
%55 = load i32, i32* @UINT_MAX
%56 = sub nsw i32 %55, 1024
store i32 %56, i32* %4
br label %57
57: ; preds = %67, %54
%58 = load i32, i32* %4
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %57
%61 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%62 = load i32, i32* %4
%63 = call i32 @snprintf(i8* %61, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %2
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%66 = call i32 @test_lookup_fail(i32 %64, i8* %65)
br label %67
67: ; preds = %60
%68 = load i32, i32* %4
%69 = add i32 %68, 1
store i32 %69, i32* %4
br label %57
70: ; preds = %57
ret void
}

LLVM IR (-O2):
@INT_MIN = global i32 0
@.str = [3 x i8] c"%d\00"
@INT_MAX = global i32 0
@.str.1 = [3 x i8] c"%u\00"
@UINT_MAX = global i32 0
define void @test_lookup(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @INT_MIN
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ %9, %5 ], [ %4, %1 ]
%7 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @test_lookup_fail(i32 %0, i8* %3)
%9 = add nsw i32 %6, 1
%10 = load i32, i32* @INT_MIN
%11 = add nsw i32 %10, 1023
%12 = icmp slt i32 %6, %11
br i1 %12, label %5, label %13
13: ; preds = %5, %13
%14 = phi i32 [ %17, %13 ], [ -1024, %5 ]
%15 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @test_lookup_fail(i32 %0, i8* %3)
%17 = add nsw i32 %14, 1
%18 = icmp eq i32 %17, 1024
br i1 %18, label %19, label %13
19: ; preds = %13
%20 = load i32, i32* @INT_MAX
%21 = add nsw i32 %20, -1024
%22 = add i32 %20, 1024
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %19, %24
%25 = phi i32 [ %28, %24 ], [ %21, %19 ]
%26 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = call i32 @test_lookup_fail(i32 %0, i8* %3)
%28 = add nuw i32 %25, 1
%29 = load i32, i32* @INT_MAX
%30 = add i32 %29, 1024
%31 = icmp ult i32 %28, %30
br i1 %31, label %24, label %32
32: ; preds = %24, %19
%33 = load i32, i32* @UINT_MAX
%34 = add nsw i32 %33, -1024
%35 = icmp eq i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %32, %36
%37 = phi i32 [ %40, %36 ], [ %34, %32 ]
%38 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = call i32 @test_lookup_fail(i32 %0, i8* %3)
%40 = add i32 %37, 1
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %36
42: ; preds = %36, %32
ret void
}