void putAlignmentPattern(unsigned char *frame, int width, int ox, int oy) {
  static const unsigned char finder[] = {
      0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa0, 0xa0, 0xa0,
      0xa1, 0xa1, 0xa0, 0xa1, 0xa0, 0xa1, 0xa1, 0xa0, 0xa0,
      0xa0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1,
  };
  int x, y;
  const unsigned char *s;
  frame += (oy - 2) * width + ox - 2;
  s = finder;
  for (y = 0; y < 5; y++) {
    for (x = 0; x < 5; x++) {
      frame[x] = s[x];
    }
    frame += width;
    s += 5;
  }
}


x86 assembly (clang, -O0):
<putAlignmentPattern>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
imul   -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11ab <putAlignmentPattern+0xab>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    1180 <putAlignmentPattern+0x80>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <putAlignmentPattern+0x52>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <putAlignmentPattern+0x41>
pop    %rbp
ret

x86 assembly (clang, -O2):
<putAlignmentPattern>:
add    $0xfffffffe,%ecx
imul   %esi,%ecx
lea    (%rdx,%rcx,1),%eax
add    $0xfffffffe,%eax
cltq
lea    (%rdi,%rax,1),%rcx
movslq %esi,%rdx
lea    (%rcx,%rdx,1),%rsi
movb   $0xa1,0x4(%rdi,%rax,1)
movl   $0xa1a1a1a1,(%rdi,%rax,1)
movl   $0xa0a0a0a1,(%rdx,%rcx,1)
movb   $0xa1,0x4(%rdx,%rcx,1)
lea    (%rsi,%rdx,1),%rax
movl   $0xa0a1a0a1,(%rdx,%rsi,1)
movb   $0xa1,0x4(%rdx,%rsi,1)
lea    (%rax,%rdx,1),%rcx
movl   $0xa0a0a0a1,(%rdx,%rax,1)
movb   $0xa1,0x4(%rdx,%rax,1)
movb   $0xa1,0x4(%rdx,%rcx,1)
movl   $0xa1a1a1a1,(%rdx,%rcx,1)
ret

LLVM IR (-O0):
@putAlignmentPattern.finder = internal constant [25 x i8] c"\A1\A1\A1\A1\A1\A1\A0\A0\A0\A1\A1\A0\A1\A0\A1\A1\A0\A0\A0\A1\A1\A1\A1\A1\A1"
define void @putAlignmentPattern(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 2
%14 = load i32, i32* %6
%15 = mul nsw i32 %13, %14
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
%18 = sub nsw i32 %17, 2
%19 = load i8*, i8** %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @putAlignmentPattern.finder, i64 0, i64 0), i8** %11
store i32 0, i32* %10
br label %22
22: ; preds = %49, %4
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 5
br i1 %24, label %25, label %52
25: ; preds = %22
store i32 0, i32* %9
br label %26
26: ; preds = %39, %25
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %42
29: ; preds = %26
%30 = load i8*, i8** %11
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = load i8*, i8** %5
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %29
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %26
42: ; preds = %26
%43 = load i32, i32* %6
%44 = load i8*, i8** %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %5
%47 = load i8*, i8** %11
%48 = getelementptr inbounds i8, i8* %47, i64 5
store i8* %48, i8** %11
br label %49
49: ; preds = %42
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %22
52: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @putAlignmentPattern(i8* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = add nsw i32 %3, -2
%6 = mul nsw i32 %5, %1
%7 = add i32 %2, -2
%8 = add i32 %7, %6
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8 -95, i8* %12
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 -96, i8* %13
%14 = getelementptr inbounds i8, i8* %12, i64 2
store i8 -96, i8* %14
%15 = getelementptr inbounds i8, i8* %12, i64 3
store i8 -96, i8* %15
%16 = getelementptr inbounds i8, i8* %12, i64 4
store i8 -95, i8* %16
%17 = getelementptr inbounds i8, i8* %12, i64 %11
store i8 -95, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 -96, i8* %18
%19 = getelementptr inbounds i8, i8* %17, i64 2
store i8 -95, i8* %19
%20 = getelementptr inbounds i8, i8* %17, i64 3
store i8 -96, i8* %20
%21 = getelementptr inbounds i8, i8* %17, i64 4
store i8 -95, i8* %21
%22 = getelementptr inbounds i8, i8* %17, i64 %11
store i8 -95, i8* %22
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 -96, i8* %23
%24 = getelementptr inbounds i8, i8* %22, i64 2
store i8 -96, i8* %24
%25 = getelementptr inbounds i8, i8* %22, i64 3
store i8 -96, i8* %25
%26 = getelementptr inbounds i8, i8* %22, i64 4
store i8 -95, i8* %26
%27 = getelementptr inbounds i8, i8* %22, i64 %11
ret void
}