#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int main() {
  unsigned long linuxgate_start = 0xffffe000;
  char *ptr = (char *)linuxgate_start;
  int i;
  for (i = 0; i < 4096; i++) {
    if (ptr[i] == '\xff' && ptr[i + 1] == '\xe4')
      printf("found jmp esp at %p\n", ptr + i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xffffe000,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1000,-0x1c(%rbp)
jge    119d <main+0x8d>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xffffffff,%eax
jne    118a <main+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xffffffe4,%eax
jne    118a <main+0x7a>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
jmp    118f <main+0x7f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <main+0x27>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffe000,%r15d
xor    %ebx,%ebx
lea    0xedc(%rip),%r14
jmp    1139 <main+0x29>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x1000,%rbx
je     115c <main+0x4c>
mov    %rbx,%rsi
add    $0x1,%rbx
cmpb   $0xff,(%r15,%rsi,1)
jne    1130 <main+0x20>
cmpb   $0xe4,0x1(%r15,%rsi,1)
jne    1130 <main+0x20>
add    %r15,%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    1130 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"found jmp esp at %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i64 4294959104, i64* %2
%5 = load i64, i64* %2
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %34, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4096
br i1 %9, label %10, label %37
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %33
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, -28
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %27, %18, %10
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %7
37: ; preds = %7
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [21 x i8] c"found jmp esp at %p\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %13
%2 = phi i64 [ 0, %0 ], [ %6, %13 ]
%3 = getelementptr inbounds i8, i8* inttoptr (i64 4294959104 to i8*), i64 %2
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, -1
%6 = add nuw nsw i64 %2, 1
br i1 %5, label %7, label %13
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* inttoptr (i64 4294959104 to i8*), i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, -28
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %13
13: ; preds = %1, %7, %11
%14 = icmp eq i64 %6, 4096
br i1 %14, label %15, label %1
15: ; preds = %13
ret i32 0
}