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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int taint_data(u_char *msg) {
  u_char *msg1 = msg;
  FILE *fp = fopen("testcase", "r");
  if (!fp) {
    fprintf(stderr, "Could not open testcase file\n");
    exit(1);
  }
  for (; fread(msg, 1, 1, fp) == 1; msg++)
    ;
  return (msg - msg1);
}


x86 assembly (clang, -O0):
<taint_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xea5(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <taint_data+0x55>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    119a <taint_data+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11cd <taint_data+0x8d>
jmp    11bc <taint_data+0x7c>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <taint_data+0x5a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<taint_data>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xeb2(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <taint_data+0x58>
mov    %rax,%r14
mov    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    $0x4,%rbx
add    $0x1,%ebp
cmp    $0x1,%eax
je     1170 <taint_data+0x30>
mov    %ebp,%eax
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(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %2
%5 = load i32*, i32** %2
store i32* %5, i32** %3
%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** %4
%7 = load i32*, i32** %4
%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 ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %20, %13
%15 = load i32*, i32** %2
%16 = load i32*, i32** %4
%17 = call i32 @fread(i32* %15, i32 1, i32 1, i32* %16)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i32*, i32** %2
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %2
br label %14
23: ; preds = %14
%24 = load i32*, i32** %2
%25 = load i32*, i32** %3
%26 = ptrtoint i32* %24 to i64
%27 = ptrtoint i32* %25 to i64
%28 = sub i64 %26, %27
%29 = sdiv exact i64 %28, 4
%30 = trunc i64 %29 to i32
ret i32 %30
}

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(i32* %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 ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1, %8
%9 = phi i32* [ %12, %8 ], [ %0, %1 ]
%10 = tail call i32 @fread(i32* %9, i32 1, i32 1, i32* %2)
%11 = icmp eq i32 %10, 1
%12 = getelementptr inbounds i32, i32* %9, i64 1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = ptrtoint i32* %9 to i64
%15 = ptrtoint i32* %0 to i64
%16 = sub i64 %14, %15
%17 = lshr exact i64 %16, 2
%18 = trunc i64 %17 to i32
ret i32 %18
}