#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*/ floyd_steinberg_dither(unsigned char *, unsigned char *,
                                          int);
unsigned char *load_image(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ save_image(char *, unsigned char *, int);
int main(int argc, char **argv) {
  if (argc < 1) {
    printf("Usage: ditherer.bin <grey4 format file>\n");
    return 1;
  }
  int num_pixels = 144 * 144;
  unsigned char *in = load_image(argv[1]);
  unsigned char *out = (unsigned char *)malloc(num_pixels / 8);
  floyd_steinberg_dither(in, out, num_pixels);
  save_image("dithered.bin", out, num_pixels / 8);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ea <main+0x9a>
movl   $0x5100,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <load_image@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <floyd_steinberg_dither@plt>
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe4b(%rip),%rdi
call   1040 <save_image@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1199 <main+0x49>
mov    0x8(%rsi),%rdi
call   1050 <load_image@plt>
mov    %rax,%r14
mov    $0xa20,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x5100,%edx
call   1070 <floyd_steinberg_dither@plt>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
mov    $0xa20,%edx
call   1040 <save_image@plt>
xor    %eax,%eax
jmp    11aa <main+0x5a>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: ditherer.bin <grey4 format file>\0A\00"
@.str.1 = [13 x i8] c"dithered.bin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %30
13: ; preds = %2
store i32 20736, i32* %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i8* @load_image(i8* %16)
store i8* %17, i8** %7
%18 = load i32, i32* %6
%19 = sdiv i32 %18, 8
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %8
%22 = load i8*, i8** %7
%23 = load i8*, i8** %8
%24 = load i32, i32* %6
%25 = call i32 @floyd_steinberg_dither(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %8
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 8
%29 = call i32 @save_image(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %13, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"dithered.bin\00"
@str = [40 x i8] c"Usage: ditherer.bin <grey4 format file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %14
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8* @load_image(i8* %8)
%10 = tail call i64 @malloc(i32 2592)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @floyd_steinberg_dither(i8* %9, i8* %11, i32 20736)
%13 = tail call i32 @save_image(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 2592)
br label %14
14: ; preds = %6, %4
%15 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %15
}