#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 *, ...);
void vuln(char *s, int offset) {
  int *ptr;
  int k, j;
  char msg[] = "Hello World!\n";
  ptr = (int *)msg;
  printf("Parsing starts at address %p\n", ptr);
  for (k = 0; k < offset; k++) {
    printf("%x ", *ptr);
    ptr++;
  }
  printf("%d words processed\nParsing ends at address %p\n", k, ptr);
  printf(s);
}


x86 assembly (clang, -O0):
<vuln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x2e(%rbp)
mov    0xed8(%rip),%eax
mov    %eax,-0x26(%rbp)
mov    0xed2(%rip),%ax
mov    %ax,-0x22(%rbp)
lea    -0x2e(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <vuln+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <vuln+0x4f>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vuln>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
movabs $0xa21646c726f57,%rax
mov    %rax,0x6(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,(%rsp)
mov    %rsp,%rbx
lea    0xec5(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r15d,%r15d
jle    1188 <vuln+0x78>
mov    %rsp,%rbx
lea    0xec8(%rip),%r12
mov    %r15d,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x4,%rbx
add    $0xffffffff,%ebp
jne    1170 <vuln+0x60>
mov    %r15d,%ebp
lea    0xea1(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.vuln.msg = [14 x i8] c"Hello World!\0A\00"
@.str = [30 x i8] c"Parsing starts at address %p\0A\00"
@.str.1 = [4 x i8] c"%x \00"
@.str.2 = [47 x i8] c"%d words processed\0AParsing ends at address %p\0A\00"
define void @vuln(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [14 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = bitcast [14 x i8]* %8 to i8*
%10 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %12)
store i32 0, i32* %6
br label %14
14: ; preds = %24, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i32 1
store i32* %23, i32** %5
br label %24
24: ; preds = %18
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %14
27: ; preds = %14
%28 = load i32, i32* %6
%29 = load i32*, i32** %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32* %29)
%31 = load i8*, i8** %3
%32 = call i32 (i8*, ...) @printf(i8* %31)
ret void
}

LLVM IR (-O2):
@__const.vuln.msg = [14 x i8] c"Hello World!\0A\00"
@.str = [30 x i8] c"Parsing starts at address %p\0A\00"
@.str.1 = [4 x i8] c"%x \00"
@.str.2 = [47 x i8] c"%d words processed\0AParsing ends at address %p\0A\00"
define void @vuln(i8* nocapture %0, i32 %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%5 = bitcast [14 x i8]* %3 to i32*
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), [14 x i8]* %3)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %16
8: ; preds = %2, %8
%9 = phi i32* [ %13, %8 ], [ %5, %2 ]
%10 = phi i32 [ %14, %8 ], [ 0, %2 ]
%11 = load i32, i32* %9
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds i32, i32* %9, i64 1
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = phi i32 [ 0, %2 ], [ %1, %8 ]
%18 = phi i32* [ %5, %2 ], [ %13, %8 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32* %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %0)
ret void
}