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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void taint_data(char *addr) {
  FILE *fp = fopen("testcase", "r");
  int i = 0;
  char special_char = '\377';
  if (!fp) {
    fprintf(stderr, "Could not find testcase file \n");
    exit(1);
  }
  for (i = 0; i < 300; i++) {
    addr[i] = fgetc(fp);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<taint_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0xff,-0x15(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <taint_data+0x58>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x12c,-0x14(%rbp)
jge    11e0 <taint_data+0x90>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <taint_data+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<taint_data>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a6 <taint_data+0x56>
mov    %rax,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x12c,%rbx
jne    1180 <taint_data+0x30>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"testcase\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Could not find testcase file \0A\00"
define void @taint_data(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
store i32 0, i32* %4
store i8 -1, i8* %5
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
store i32 0, i32* %4
br label %14
14: ; preds = %24, %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 300
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32*, i32** %3
%19 = call signext i8 @fgetc(i32* %18)
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %17
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %14
27: ; preds = %14
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"testcase\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Could not find testcase file \0A\00"
define void @taint_data(i8* nocapture writeonly %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ 0, %1 ]
%10 = tail call signext i8 @fgetc(i32* %2)
%11 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %10, i8* %11
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, 300
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = tail call i32 @fclose(i32* %2)
ret void
}