#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 */
char EOF;
int atoi(char *);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ shade(char, char *);
int main(int argc, char *argv[]) {
  int x = 0, y = 0;
  int width, height;
  char c;
  if (argc != 3) {
    printf("Requires two (2) arguments; width and height\n");
    printf("Usage: %s [width] [height]\n", argv[0]);
    return 1;
  }
  width = atoi(argv[1]);
  height = atoi(argv[2]);
  while (c != EOF) {
    c = getchar();
    if (!shade(c, &c)) {
      printf("\nERROR: Invalid character '%c'.\n", c);
      return 1;
    }
    printf("%c", c);
    x++;
    if (x >= width) {
      printf("\n");
      x = 0;
      y++;
    }
    if (y >= height) {
      break;
    }
  }
  printf("\n");
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119d <main+0x5d>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x141>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x21(%rbp),%eax
mov    0x2e20(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     126c <main+0x12c>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x21(%rbp)
lea    -0x21(%rbp),%rsi
movsbl -0x21(%rbp),%edi
call   1030 <shade@plt>
cmp    $0x0,%eax
jne    1211 <main+0xd1>
movsbl -0x21(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x141>
movsbl -0x21(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1256 <main+0x116>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     1267 <main+0x127>
jmp    126c <main+0x12c>
jmp    11bd <main+0x7d>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    120a <main+0xaa>
mov    0x8(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
xor    %eax,%eax
test   %al,%al
jne    11fc <main+0x9c>
lea    0x7(%rsp),%r14
mov    0x2e47(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %al,0x7(%rsp)
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <shade@plt>
movsbl 0x7(%rsp),%esi
test   %eax,%eax
je     123c <main+0xdc>
mov    %esi,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %r12d,%ebp
jl     11ed <main+0x8d>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
xor    %ebp,%ebp
cmp    %r13d,%ebx
jge    11fc <main+0x9c>
movzbl 0x7(%rsp),%eax
cmp    (%r15),%al
jne    11b0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
jmp    122d <main+0xcd>
lea    0xe2c(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%rsi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1228 <main+0xc8>

LLVM IR (-O0):
@.str = [46 x i8] c"Requires two (2) arguments; width and height\0A\00"
@.str.1 = [28 x i8] c"Usage: %s [width] [height]\0A\00"
@EOF = global i8 0
@.str.2 = [33 x i8] c"\0AERROR: Invalid character '%c'.\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %64
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
br label %28
28: ; preds = %61, %19
%29 = load i8, i8* %10
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %62
34: ; preds = %28
%35 = call signext i8 (...) @getchar()
store i8 %35, i8* %10
%36 = load i8, i8* %10
%37 = call i32 @shade(i8 signext %36, i8* %10)
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %34
%40 = load i8, i8* %10
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %41)
store i32 1, i32* %3
br label %64
43: ; preds = %34
%44 = load i8, i8* %10
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = load i32, i32* %8
%51 = icmp sge i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %43
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %56
56: ; preds = %52, %43
%57 = load i32, i32* %7
%58 = load i32, i32* %9
%59 = icmp sge i32 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %56
br label %62
61: ; preds = %56
br label %28
62: ; preds = %60, %28
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %64
64: ; preds = %62, %39, %13
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"Usage: %s [width] [height]\0A\00"
@EOF = global i8 0
@.str.2 = [33 x i8] c"\0AERROR: Invalid character '%c'.\0A\00"
@str = [45 x i8] c"Requires two (2) arguments; width and height\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %44
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
br i1 undef, label %42, label %16
16: ; preds = %9, %38
%17 = phi i32 [ %36, %38 ], [ 0, %9 ]
%18 = phi i32 [ %35, %38 ], [ 0, %9 ]
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %3
%20 = call i32 @shade(i8 signext %19, i8* %3)
%21 = icmp eq i32 %20, 0
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
br i1 %21, label %24, label %27
24: ; preds = %16
%25 = sext i8 %22 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %44
27: ; preds = %16
%28 = call i32 @putchar(i32 %23)
%29 = add nsw i32 %17, 1
%30 = icmp slt i32 %29, %12
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = call i32 @putchar(i32 10)
%33 = add nsw i32 %18, 1
br label %34
34: ; preds = %31, %27
%35 = phi i32 [ %33, %31 ], [ %18, %27 ]
%36 = phi i32 [ 0, %31 ], [ %29, %27 ]
%37 = icmp slt i32 %35, %15
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8, i8* %3
%40 = load i8, i8* @EOF
%41 = icmp eq i8 %39, %40
br i1 %41, label %42, label %16
42: ; preds = %38, %34, %9
%43 = call i32 @putchar(i32 10)
br label %44
44: ; preds = %42, %24, %5
%45 = phi i32 [ 1, %5 ], [ 0, %42 ], [ 1, %24 ]
ret i32 %45
}