#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 /*<<< orphan*/ free(char *);
int fs_write(int, char *, size_t);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
int check_test_pattern(int file, size_t nbytes) {
  char *buffer = malloc(nbytes);
  if (fs_write(file, buffer, nbytes) == -1) {
    fprintf(stderr, "check_test_pattern: Read failed.\n");
    free(buffer);
    return -1;
  }
  int i;
  for (i = 0; i < nbytes; i++) {
    if (buffer[i] != 'a' + (i % ('z' - 'a'))) {
      fprintf(stderr, "check_test_pattern: Pattern mismatch at byte %d.\n", i);
      free(buffer);
      return -1;
    }
  }
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<check_test_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <fs_write@plt>
cmp    $0xffffffff,%eax
jne    11a1 <check_test_pattern+0x61>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <check_test_pattern+0xf0>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1220 <check_test_pattern+0xe0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
add    $0x61,%edx
cmp    %edx,%eax
je     120d <check_test_pattern+0xcd>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <check_test_pattern+0xf0>
jmp    1212 <check_test_pattern+0xd2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <check_test_pattern+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_test_pattern>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <fs_write@plt>
cmp    $0xffffffff,%eax
je     11a8 <check_test_pattern+0x68>
test   %rbx,%rbx
je     119c <check_test_pattern+0x5c>
xor    %edx,%edx
nopl   (%rax)
mov    %edx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,4),%eax
movsbl (%r14,%rdx,1),%ecx
mov    %edx,%esi
sub    %eax,%esi
add    $0x61,%esi
cmp    %ecx,%esi
jne    11c1 <check_test_pattern+0x81>
add    $0x1,%rdx
cmp    %rdx,%rbx
jne    1170 <check_test_pattern+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11e5 <check_test_pattern+0xa5>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d8 <check_test_pattern+0x98>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"check_test_pattern: Read failed.\0A\00"
@.str.1 = [50 x i8] c"check_test_pattern: Pattern mismatch at byte %d.\0A\00"
define i32 @check_test_pattern(i32 %0, i64 %1) {
%3 = tail call i8* @malloc(i64 %1)
%4 = tail call i32 @fs_write(i32 %0, i8* %3, i64 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = icmp eq i64 %1, 0
br i1 %7, label %29, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @free(i8* %3)
br label %31
12: ; preds = %6, %26
%13 = phi i64 [ %27, %26 ], [ 0, %6 ]
%14 = getelementptr inbounds i8, i8* %3, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = trunc i64 %13 to i32
%18 = urem i32 %17, 25
%19 = add nuw nsw i32 %18, 97
%20 = icmp eq i32 %19, %16
br i1 %20, label %26, label %21
21: ; preds = %12
%22 = trunc i64 %13 to i32
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%25 = tail call i32 @free(i8* %3)
br label %31
26: ; preds = %12
%27 = add nuw i64 %13, 1
%28 = icmp eq i64 %27, %1
br i1 %28, label %29, label %12
29: ; preds = %26, %6
%30 = tail call i32 @free(i8* %3)
br label %31
31: ; preds = %21, %29, %8
%32 = phi i32 [ -1, %8 ], [ -1, %21 ], [ 0, %29 ]
ret i32 %32
}