#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*/ printf(char *);
void printGrid(int *g, int M, int N) {
  int l, vstrips;
  l = 0;
  vstrips = (N + 29) / 30;
  for (int i = 0; i < M; i++) {
    int n = N;
    for (int j = 0; j < vstrips; j++) {
      int c = g[2 * (l + j * M)];
      for (int k = 30; k && n; k--, n--)
        if (c & (1 << k))
          printf("X");
        else
          printf("-");
    }
    l++;
    printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printGrid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1d,%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123b <printGrid+0x12b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1218 <printGrid+0x108>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x24(%rbp),%edx
imul   -0xc(%rbp),%edx
add    %edx,%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
movl   $0x1e,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
je     11a2 <printGrid+0x92>
cmpl   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11b2 <printGrid+0xa2>
jmp    1205 <printGrid+0xf5>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11dd <printGrid+0xcd>
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <printGrid+0xd9>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
jmp    11ee <printGrid+0xde>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1189 <printGrid+0x79>
jmp    120a <printGrid+0xfa>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <printGrid+0x4a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <printGrid+0x31>
lea    0xdc2(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printGrid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rdi,0x20(%rsp)
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    1215 <printGrid+0x105>
mov    0x10(%rsp),%rcx
lea    0x1d(%rcx),%eax
cltq
imul   $0xffffffff88888889,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
add    $0x1d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x4,%eax
add    %ecx,%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0x2d,%ebx
jmp    119f <printGrid+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%r14
add    $0x1,%r14d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,0x18(%rsp)
cmp    0xc(%rsp),%r14d
je     1215 <printGrid+0x105>
cmpl   $0x0,0x10(%rsp)
jle    1180 <printGrid+0x70>
xor    %r14d,%r14d
mov    0x10(%rsp),%r15
jmp    11bc <printGrid+0xac>
xor    %r15d,%r15d
add    $0x1,%r14
cmp    %rbp,%r14
je     1180 <printGrid+0x70>
test   %r15d,%r15d
je     11b0 <printGrid+0xa0>
mov    %r14d,%eax
imul   0xc(%rsp),%eax
add    0x18(%rsp),%eax
add    %eax,%eax
cltq
mov    0x20(%rsp),%rcx
mov    (%rcx,%rax,4),%r12d
xor    %r13d,%r13d
nopl   (%rax)
lea    0x1e(%r13),%eax
movzbl %al,%eax
bt     %eax,%r12d
mov    $0x58,%edi
cmovae %ebx,%edi
call   1030 <putchar@plt>
lea    -0x1(%r13),%eax
cmp    $0xffffffe3,%r13d
je     1210 <printGrid+0x100>
lea    (%r15,%r13,1),%ecx
add    $0xffffffff,%ecx
mov    %eax,%r13d
test   %ecx,%ecx
jne    11e0 <printGrid+0xd0>
add    %eax,%r15d
jmp    11b3 <printGrid+0xa3>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"X\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printGrid(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 29
%16 = sdiv i32 %15, 30
store i32 %16, i32* %8
store i32 0, i32* %9
br label %17
17: ; preds = %70, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %73
21: ; preds = %17
%22 = load i32, i32* %6
store i32 %22, i32* %10
store i32 0, i32* %11
br label %23
23: ; preds = %63, %21
%24 = load i32, i32* %11
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %66
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = load i32, i32* %7
%30 = load i32, i32* %11
%31 = load i32, i32* %5
%32 = mul nsw i32 %30, %31
%33 = add nsw i32 %29, %32
%34 = mul nsw i32 2, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %28, i64 %35
%37 = load i32, i32* %36
store i32 %37, i32* %12
store i32 30, i32* %13
br label %38
38: ; preds = %57, %27
%39 = load i32, i32* %13
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br label %44
44: ; preds = %41, %38
%45 = phi i1 [ false, %38 ], [ %43, %41 ]
br i1 %45, label %46, label %62
46: ; preds = %44
%47 = load i32, i32* %12
%48 = load i32, i32* %13
%49 = shl i32 1, %48
%50 = and i32 %47, %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %56
54: ; preds = %46
%55 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
br label %57
57: ; preds = %56
%58 = load i32, i32* %13
%59 = add nsw i32 %58, -1
store i32 %59, i32* %13
%60 = load i32, i32* %10
%61 = add nsw i32 %60, -1
store i32 %61, i32* %10
br label %38
62: ; preds = %44
br label %63
63: ; preds = %62
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
br label %23
66: ; preds = %23
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
%69 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %70
70: ; preds = %66
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %17
73: ; preds = %17
%74 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
define void @printGrid(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = add nsw i32 %2, 29
%7 = sdiv i32 %6, 30
%8 = icmp sgt i32 %2, 0
%9 = call i32 @llvm.smax.i32(i32 %7, i32 1)
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %5, %15
%12 = phi i32 [ 0, %5 ], [ %16, %15 ]
br i1 %8, label %19, label %15
13: ; preds = %15, %3
%14 = tail call i32 @putchar(i32 10)
ret void
15: ; preds = %30, %11
%16 = add nuw nsw i32 %12, 1
%17 = tail call i32 @putchar(i32 10)
%18 = icmp eq i32 %16, %1
br i1 %18, label %13, label %11
19: ; preds = %11, %30
%20 = phi i64 [ %32, %30 ], [ 0, %11 ]
%21 = phi i32 [ %31, %30 ], [ %2, %11 ]
%22 = trunc i64 %20 to i32
%23 = mul nsw i32 %22, %1
%24 = add nsw i32 %23, %12
%25 = shl nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %0, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %21, 0
br i1 %29, label %30, label %34
30: ; preds = %34, %19
%31 = phi i32 [ 0, %19 ], [ %43, %34 ]
%32 = add nuw nsw i64 %20, 1
%33 = icmp eq i64 %32, %10
br i1 %33, label %15, label %19
34: ; preds = %19, %34
%35 = phi i32 [ %42, %34 ], [ 30, %19 ]
%36 = phi i32 [ %43, %34 ], [ %21, %19 ]
%37 = shl nuw i32 1, %35
%38 = and i32 %37, %28
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i32 45, i32 88
%41 = tail call i32 @putchar(i32 %40)
%42 = add nsw i32 %35, -1
%43 = add nsw i32 %36, -1
%44 = icmp ne i32 %42, 0
%45 = icmp ne i32 %43, 0
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %34, label %30
}