#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 write_test_pattern(int file, size_t nbytes) {
  char *buffer = malloc(nbytes);
  int i;
  for (i = 0; i < nbytes; i++) {
    buffer[i] = 'a' + (i % ('z' - 'a'));
  }
  if (fs_write(file, buffer, nbytes) == -1) {
    fprintf(stderr, "write_test_pattern: Write failed.\n");
    free(buffer);
    return -1;
  }
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<write_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)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1198 <write_test_pattern+0x58>
mov    -0x1c(%rbp),%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <write_test_pattern+0x23>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <fs_write@plt>
cmp    $0xffffffff,%eax
jne    11db <write_test_pattern+0x9b>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <write_test_pattern+0xab>
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):
<write_test_pattern>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %r14,%r14
je     163a <write_test_pattern+0x4fa>
cmp    $0x10,%r14
jae    116d <write_test_pattern+0x2d>
xor    %eax,%eax
jmp    15ff <write_test_pattern+0x4bf>
mov    %r14,%rax
and    $0xfffffffffffffff0,%rax
lea    -0x10(%rax),%rdx
mov    %rdx,%rcx
shr    $0x4,%rcx
add    $0x1,%rcx
test   %rdx,%rdx
je     167d <write_test_pattern+0x53d>
mov    %rcx,%rsi
and    $0xfffffffffffffffe,%rsi
movdqa 0xe75(%rip),%xmm4
movdqa 0xe7c(%rip),%xmm14
movdqa 0xe84(%rip),%xmm6
movdqa 0xe8b(%rip),%xmm13
xor    %edx,%edx
movdqa 0xe90(%rip),%xmm12
movdqa 0xe97(%rip),%xmm11
movdqa 0xe9e(%rip),%xmm8
movdqa 0xea5(%rip),%xmm9
movdqa 0xeac(%rip),%xmm10
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa %xmm14,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm14,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm0
punpckldq %xmm0,%xmm2
movdqa %xmm14,%xmm0
psubd  %xmm2,%xmm0
movdqa %xmm4,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm4,%xmm2
pmuludq %xmm12,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm4,%xmm2
psubd  %xmm1,%xmm2
packuswb %xmm2,%xmm0
movdqa %xmm13,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm13,%xmm2
pmuludq %xmm12,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm13,%xmm2
psubd  %xmm1,%xmm2
movdqa %xmm6,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm6,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
movdqa %xmm6,%xmm5
psubd  %xmm1,%xmm5
packuswb %xmm5,%xmm2
packuswb %xmm0,%xmm2
paddb  %xmm8,%xmm2
movdqu %xmm2,(%r15,%rdx,1)
movdqa %xmm6,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm13,%xmm0
paddd  %xmm9,%xmm0
movdqa %xmm4,%xmm5
paddd  %xmm9,%xmm5
movdqa %xmm14,%xmm3
paddd  %xmm9,%xmm3
movdqa %xmm3,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm3,%xmm7
pmuludq %xmm12,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm1,%xmm3
movdqa %xmm5,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm5,%xmm7
pmuludq %xmm12,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm1,%xmm5
packuswb %xmm5,%xmm3
movdqa %xmm0,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psubd  %xmm1,%xmm0
movdqa %xmm2,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm2,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psubd  %xmm1,%xmm2
packuswb %xmm2,%xmm0
packuswb %xmm3,%xmm0
paddb  %xmm8,%xmm0
movdqu %xmm0,0x10(%r15,%rdx,1)
add    $0x20,%rdx
paddd  %xmm10,%xmm13
paddd  %xmm10,%xmm6
paddd  %xmm10,%xmm14
paddd  %xmm10,%xmm4
add    $0xfffffffffffffffe,%rsi
jne    11f0 <write_test_pattern+0xb0>
movdqa %xmm14,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm14,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm14
movdqa %xmm4,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm4,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm4
packuswb %xmm4,%xmm14
movdqa %xmm13,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm13,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm13
movdqa %xmm6,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm6,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm6
packuswb %xmm6,%xmm13
packuswb %xmm14,%xmm13
paddb  0xa81(%rip),%xmm13
test   $0x1,%cl
je     15fa <write_test_pattern+0x4ba>
movdqu %xmm13,(%r15,%rdx,1)
cmp    %r14,%rax
je     163a <write_test_pattern+0x4fa>
mov    %r15,%rcx
add    %rax,%rcx
lea    0x61(%rax),%edx
mov    %r14,%rsi
sub    %rax,%rsi
xchg   %ax,%ax
mov    %eax,%edi
imul   $0x51eb851f,%rdi,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,4),%edi
lea    (%rdi,%rdi,4),%edi
mov    %edx,%ebx
sub    %dil,%bl
mov    %bl,(%rcx)
add    $0x1,%rcx
add    $0x1,%dl
add    $0x1,%eax
add    $0xffffffffffffffff,%rsi
jne    1610 <write_test_pattern+0x4d0>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <fs_write@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    1668 <write_test_pattern+0x528>
mov    0x298b(%rip),%rax
mov    (%rax),%edi
lea    0xa42(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0x97a(%rip),%xmm13
xor    %edx,%edx
test   $0x1,%cl
jne    15f4 <write_test_pattern+0x4b4>
jmp    15fa <write_test_pattern+0x4ba>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"write_test_pattern: Write failed.\0A\00"
define i32 @write_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
store i32 0, i32* %7
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i32, i32* %7
%17 = srem i32 %16, 25
%18 = add nsw i32 97, %17
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %15
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %10
27: ; preds = %10
%28 = load i32, i32* %4
%29 = load i8*, i8** %6
%30 = load i64, i64* %5
%31 = call i32 @fs_write(i32 %28, i8* %29, i64 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
store i32 -1, i32* %3
br label %41
38: ; preds = %27
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %33
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"write_test_pattern: Write failed.\0A\00"
define i32 @write_test_pattern(i32 %0, i64 %1) {
%3 = tail call i8* @malloc(i64 %1)
%4 = icmp eq i64 %1, 0
br i1 %4, label %60, label %5
5: ; preds = %2
%6 = icmp ult i64 %1, 16
br i1 %6, label %49, label %7
7: ; preds = %5
%8 = and i64 %1, -16
%9 = add i64 %8, -16
%10 = lshr exact i64 %9, 4
%11 = add nuw nsw i64 %10, 1
%12 = and i64 %11, 1
%13 = icmp eq i64 %9, 0
br i1 %13, label %40, label %14
14: ; preds = %7
%15 = and i64 %11, 2305843009213693950
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 0, %14 ], [ %32, %16 ]
%18 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %14 ], [ %33, %16 ]
%19 = phi i64 [ 0, %14 ], [ %34, %16 ]
%20 = urem <16 x i32> %18, <i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25>
%21 = trunc <16 x i32> %20 to <16 x i8>
%22 = add nuw nsw <16 x i8> %21, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
%23 = getelementptr inbounds i8, i8* %3, i64 %17
%24 = bitcast i8* %23 to <16 x i8>*
store <16 x i8> %22, <16 x i8>* %24
%25 = or i64 %17, 16
%26 = add <16 x i32> %18, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%27 = urem <16 x i32> %26, <i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25>
%28 = trunc <16 x i32> %27 to <16 x i8>
%29 = add nuw nsw <16 x i8> %28, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
%30 = getelementptr inbounds i8, i8* %3, i64 %25
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %29, <16 x i8>* %31
%32 = add nuw i64 %17, 32
%33 = add <16 x i32> %18, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%34 = add i64 %19, 2
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %16
36: ; preds = %16
%37 = urem <16 x i32> %33, <i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25, i32 25>
%38 = trunc <16 x i32> %37 to <16 x i8>
%39 = add nuw <16 x i8> %38, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
br label %40
40: ; preds = %36, %7
%41 = phi i64 [ 0, %7 ], [ %32, %36 ]
%42 = phi <16 x i8> [ <i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112>, %7 ], [ %39, %36 ]
%43 = icmp eq i64 %12, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = getelementptr inbounds i8, i8* %3, i64 %41
%46 = bitcast i8* %45 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %46
br label %47
47: ; preds = %40, %44
%48 = icmp eq i64 %8, %1
br i1 %48, label %60, label %49
49: ; preds = %5, %47
%50 = phi i64 [ 0, %5 ], [ %8, %47 ]
br label %51
51: ; preds = %49, %51
%52 = phi i64 [ %58, %51 ], [ %50, %49 ]
%53 = trunc i64 %52 to i32
%54 = urem i32 %53, 25
%55 = trunc i32 %54 to i8
%56 = add nuw nsw i8 %55, 97
%57 = getelementptr inbounds i8, i8* %3, i64 %52
store i8 %56, i8* %57
%58 = add nuw nsw i64 %52, 1
%59 = icmp eq i64 %58, %1
br i1 %59, label %60, label %51
60: ; preds = %51, %47, %2
%61 = tail call i32 @fs_write(i32 %0, i8* %3, i64 %1)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = tail call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %66
66: ; preds = %60, %63
%67 = phi i32 [ -1, %63 ], [ 0, %60 ]
%68 = tail call i32 @free(i8* %3)
ret i32 %67
}