#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*/ fprintf(int /*<<< orphan*/, char *, int, char, char);
int /*<<< orphan*/ stdout;
int test_loads(char *correct_values, void *addr, int num_vals) {
  int num_failures = 0;
  char *mmap_data = (char *)addr;
  for (int i = 0; i < num_vals; i++) {
    if (mmap_data[i] != correct_values[i]) {
      fprintf(stdout, "FAILED: mmap_data[%d] = %d, should be %d\n", i,
              mmap_data[i], correct_values[i]);
      num_failures++;
    }
  }
  return num_failures;
}


x86 assembly (clang, -O0):
<test_loads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b4 <test_loads+0xa4>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11a1 <test_loads+0x91>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%r8
lea    0xe75(%rip),%rsi
movsbl %cl,%ecx
movsbl (%rax,%r8,1),%r8d
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a6 <test_loads+0x96>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1139 <test_loads+0x29>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_loads>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1176 <test_loads+0x66>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r13d
xor    %ebx,%ebx
lea    0xecf(%rip),%r12
xor    %ebp,%ebp
jmp    1149 <test_loads+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     1178 <test_loads+0x68>
movzbl (%r14,%rbx,1),%eax
movzbl (%r15,%rbx,1),%edx
cmp    %dl,%al
je     1140 <test_loads+0x30>
mov    0x2e82(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%ecx
movsbl %dl,%r8d
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
add    $0x1,%ebp
jmp    1140 <test_loads+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [42 x i8] c"FAILED: mmap_data[%d] = %d, should be %d\0A\00"
define i32 @test_loads(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
store i32 0, i32* %9
br label %11
11: ; preds = %46, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8*, i8** %4
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %21, %27
br i1 %28, label %29, label %45
29: ; preds = %15
%30 = load i32, i32* @stdout
%31 = load i32, i32* %9
%32 = load i8*, i8** %8
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %4
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %31, i8 signext %36, i8 signext %41)
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %45
45: ; preds = %29, %15
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %11
49: ; preds = %11
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [42 x i8] c"FAILED: mmap_data[%d] = %d, should be %d\0A\00"
define i32 @test_loads(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %22, %3
%8 = phi i32 [ 0, %3 ], [ %23, %22 ]
ret i32 %8
9: ; preds = %5, %22
%10 = phi i64 [ 0, %5 ], [ %24, %22 ]
%11 = phi i32 [ 0, %5 ], [ %23, %22 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 %10
%15 = load i8, i8* %14
%16 = icmp eq i8 %13, %15
br i1 %16, label %22, label %17
17: ; preds = %9
%18 = load i32, i32* @stdout
%19 = trunc i64 %10 to i32
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %19, i8 signext %13, i8 signext %15)
%21 = add nsw i32 %11, 1
br label %22
22: ; preds = %9, %17
%23 = phi i32 [ %21, %17 ], [ %11, %9 ]
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %7, label %9
}