#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int taint_data() {
  char msg[1];
  int count = 0;
  FILE *fp = fopen("testcase", "r");
  if (!fp) {
    fprintf(stderr, "Could not open testcase file\n");
    exit(1);
  }
  for (; fread(msg, 1, 1, fp) == 1; count++)
    ;
  return count;
}


x86 assembly (clang, -O0):
<taint_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <taint_data+0x50>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1195 <taint_data+0x55>
lea    -0x1(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11c5 <taint_data+0x85>
jmp    11b7 <taint_data+0x77>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1195 <taint_data+0x55>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<taint_data>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <taint_data+0x58>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
lea    0xf(%rsp),%r14
nopl   (%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
add    $0x1,%ebp
cmp    $0x1,%eax
je     1170 <taint_data+0x30>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <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 = [30 x i8] c"Could not open testcase file\0A\00"
define i32 @taint_data() {
%1 = alloca [1 x i8]
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %2
%4 = 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* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %18, %11
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %13, i32 1, i32 1, i32* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %12
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %12
21: ; preds = %12
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"testcase\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Could not open testcase file\0A\00"
define i32 @taint_data() {
%1 = alloca [1 x i8]
%2 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0, %9
%10 = phi i32 [ %13, %9 ], [ 0, %0 ]
%11 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %3)
%12 = icmp eq i32 %11, 1
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %9, label %14
14: ; preds = %9
ret i32 %10
}