#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 CHAR_BIT;
int /*<<< orphan*/ print_binary(unsigned char);
int /*<<< orphan*/ printf(char *);
void print_screen(unsigned char screen[], int screen_length, int width) {
  int rows = (screen_length * CHAR_BIT) / width;
  int cols = width / CHAR_BIT;
  int i;
  for (i = 0; i < rows; i++) {
    int j;
    if (cols > 0) {
      print_binary(screen[i * cols]);
    }
    for (j = 1; j < cols; j++) {
      printf(" | ");
      print_binary(screen[i * cols + j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ea4(%rip),%rcx
imul   (%rcx),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e90(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11eb <print_screen+0xcb>
cmpl   $0x0,-0x18(%rbp)
jle    118a <print_screen+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <print_binary@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d1 <print_screen+0xb1>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <print_binary@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1191 <print_screen+0x71>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <print_screen+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_screen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%eax
mov    %rdi,(%rsp)
mov    0x2e93(%rip),%rcx
mov    (%rcx),%esi
imul   %esi,%eax
cltd
idiv   %ebp
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %esi
test   %ecx,%ecx
jle    11fd <print_screen+0xcd>
mov    %eax,%r13d
cltq
mov    %ecx,%ecx
mov    %rcx,0x10(%rsp)
mov    %rax,0x8(%rsp)
mov    %eax,%ebp
xor    %r14d,%r14d
lea    0xe7f(%rip),%rbx
mov    (%rsp),%r12
jmp    11aa <print_screen+0x7a>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    0x8(%rsp),%r12
cmp    0x10(%rsp),%r14
je     11fd <print_screen+0xcd>
test   %r13d,%r13d
jle    11c5 <print_screen+0x95>
mov    %r14,%rax
imul   0x8(%rsp),%rax
mov    (%rsp),%rcx
movzbl (%rcx,%rax,1),%edi
call   1050 <print_binary@plt>
cmp    $0x2,%r13d
jl     1190 <print_screen+0x60>
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <printf@plt>
movzbl (%r12,%r15,1),%edi
call   1050 <print_binary@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    11e0 <print_screen+0xb0>
jmp    1190 <print_screen+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [4 x i8] c" | \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_screen(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* @CHAR_BIT
%13 = mul nsw i32 %11, %12
%14 = load i32, i32* %6
%15 = sdiv i32 %13, %14
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = load i32, i32* @CHAR_BIT
%18 = sdiv i32 %16, %17
store i32 %18, i32* %8
store i32 0, i32* %9
br label %19
19: ; preds = %57, %3
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %60
23: ; preds = %19
%24 = load i32, i32* %8
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i32, i32* %9
%29 = load i32, i32* %8
%30 = mul nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @print_binary(i8 zeroext %33)
br label %35
35: ; preds = %26, %23
store i32 1, i32* %10
br label %36
36: ; preds = %52, %35
%37 = load i32, i32* %10
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%42 = load i8*, i8** %4
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %10
%47 = add nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %42, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @print_binary(i8 zeroext %50)
br label %52
52: ; preds = %40
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %36
55: ; preds = %36
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %19
60: ; preds = %19
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [4 x i8] c" | \00"
define void @print_screen(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @CHAR_BIT
%5 = mul nsw i32 %4, %1
%6 = sdiv i32 %5, %2
%7 = sdiv i32 %2, %4
%8 = icmp sgt i32 %6, 0
br i1 %8, label %9, label %38
9: ; preds = %3
%10 = icmp sgt i32 %7, 0
%11 = icmp sgt i32 %7, 1
%12 = sext i32 %7 to i64
%13 = zext i32 %6 to i64
%14 = zext i32 %7 to i64
br label %15
15: ; preds = %9, %34
%16 = phi i64 [ 0, %9 ], [ %36, %34 ]
br i1 %10, label %17, label %22
17: ; preds = %15
%18 = mul nsw i64 %16, %12
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @print_binary(i8 zeroext %20)
br label %22
22: ; preds = %17, %15
br i1 %11, label %23, label %34
23: ; preds = %22
%24 = mul nsw i64 %16, %12
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 1, %23 ], [ %32, %25 ]
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%28 = add nsw i64 %26, %24
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = tail call i32 @print_binary(i8 zeroext %30)
%32 = add nuw nsw i64 %26, 1
%33 = icmp eq i64 %32, %14
br i1 %33, label %34, label %25
34: ; preds = %25, %22
%35 = tail call i32 @putchar(i32 10)
%36 = add nuw nsw i64 %16, 1
%37 = icmp eq i64 %36, %13
br i1 %37, label %38, label %15
38: ; preds = %34, %3
ret void
}