#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 */
typedef int uint32_t;

/* Variables and functions */
int EOF;
int atoi(char const *);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char const *argv[]) {
  int red, green, blue;
  uint32_t image_width, image_height;
  uint32_t char_width = 0;
  uint32_t total_char_width = 0;
  bool first = true;
  bool found_width = false;
  if (argc != 3) {
    printf("You need to specify the image width and height (oh, and provide a "
           "24 bit RGB image on stdin).\n");
    return 1;
  }
  image_width = atoi(argv[1]);
  image_height = atoi(argv[2]);
  while (image_width) {
    red = getchar();
    if (red == EOF)
      return (0);
    green = getchar();
    if (green == EOF)
      return (1);
    blue = getchar();
    if (blue == EOF)
      return (1);
    char_width++;
    if (red == 0xff && green == 0xff && blue == 0xff) {
      found_width = true;
      printf("convert -crop %ux%u+%u+0 font.png rusk.png\n", char_width,
             image_height, total_char_width);
      total_char_width += char_width;
      char_width = 0;
    }
    image_width--;
  }
  if (found_width) {
    printf(" };\n");
    if (total_char_width != atoi(argv[1])) {
      printf("Not sure if this image is correct\n");
    }
  } else {
    printf("Are you sure this is a font width file?\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1186 <main+0x56>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x1c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1294 <main+0x164>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11d8 <main+0xa8>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <main+0x1c4>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
jne    1200 <main+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x1c4>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
jne    1228 <main+0xf8>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x1c4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0xff,-0x14(%rbp)
jne    1286 <main+0x156>
cmpl   $0xff,-0x18(%rbp)
jne    1286 <main+0x156>
cmpl   $0xff,-0x1c(%rbp)
jne    1286 <main+0x156>
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11a6 <main+0x76>
cmpl   $0x0,-0x34(%rbp)
je     12df <main+0x1af>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
je     12da <main+0x1aa>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ed <main+0x1bd>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1257 <main+0x117>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r13d
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,0xc(%rsp)
lea    0xeb2(%rip),%rdi
test   %r13d,%r13d
je     1265 <main+0x125>
mov    %rbx,0x10(%rsp)
mov    0x2e59(%rip),%rbx
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
xor    %r14d,%r14d
jmp    11bd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rbx
add    $0xffffffff,%r13d
je     1281 <main+0x141>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     127d <main+0x13d>
mov    %eax,%r12d
mov    %r14d,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %rbx,%r14
mov    $0x1,%ebx
cmp    (%r14),%eax
je     126c <main+0x12c>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
je     126c <main+0x12c>
mov    %r14,%rcx
mov    %ebp,%r14d
add    $0x1,%r14d
cmp    $0xff,%r12d
jne    11b0 <main+0x70>
cmp    $0xff,%r15d
jne    11b0 <main+0x70>
cmp    $0xff,%eax
mov    %rcx,%rbx
jne    11b3 <main+0x73>
lea    0xdda(%rip),%rdi
mov    %r14d,%esi
mov    0xc(%rsp),%edx
mov    %rbx,%r15
mov    0x4(%rsp),%ebx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    %r14d,%ebx
mov    %ebx,0x4(%rsp)
mov    %r15,%rbx
movl   $0x1,0x8(%rsp)
xor    %r14d,%r14d
jmp    11b3 <main+0x73>
mov    $0x1,%ebx
lea    0xe17(%rip),%rdi
jmp    1267 <main+0x127>
xor    %ebx,%ebx
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    126c <main+0x12c>
cmpl   $0x0,0x8(%rsp)
je     12b3 <main+0x173>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
xor    %ebx,%ebx
cmp    %eax,0x4(%rsp)
je     126c <main+0x12c>
lea    0xda7(%rip),%rdi
jmp    1267 <main+0x127>
xor    %ebx,%ebx
lea    0xd70(%rip),%rdi
jmp    1267 <main+0x127>

LLVM IR (-O0):
@.str = [95 x i8] c"You need to specify the image width and height (oh, and provide a 24 bit RGB image on stdin).\0A\00"
@EOF = global i32 0
@.str.1 = [44 x i8] c"convert -crop %ux%u+%u+0 font.png rusk.png\0A\00"
@.str.2 = [5 x i8] c" };\0A\00"
@.str.3 = [35 x i8] c"Not sure if this image is correct\0A\00"
@.str.4 = [41 x i8] c"Are you sure this is a font width file?\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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %12
store i32 1, i32* %13
store i32 0, i32* %14
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %88
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* %9
%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* %10
br label %28
28: ; preds = %68, %19
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %71
31: ; preds = %28
%32 = call i32 (...) @getchar()
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 0, i32* %3
br label %88
37: ; preds = %31
%38 = call i32 (...) @getchar()
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 1, i32* %3
br label %88
43: ; preds = %37
%44 = call i32 (...) @getchar()
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 1, i32* %3
br label %88
49: ; preds = %43
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
%52 = load i32, i32* %6
%53 = icmp eq i32 %52, 255
br i1 %53, label %54, label %68
54: ; preds = %49
%55 = load i32, i32* %7
%56 = icmp eq i32 %55, 255
br i1 %56, label %57, label %68
57: ; preds = %54
%58 = load i32, i32* %8
%59 = icmp eq i32 %58, 255
br i1 %59, label %60, label %68
60: ; preds = %57
store i32 1, i32* %14
%61 = load i32, i32* %11
%62 = load i32, i32* %10
%63 = load i32, i32* %12
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %62, i32 %63)
%65 = load i32, i32* %11
%66 = load i32, i32* %12
%67 = add nsw i32 %66, %65
store i32 %67, i32* %12
store i32 0, i32* %11
br label %68
68: ; preds = %60, %57, %54, %49
%69 = load i32, i32* %9
%70 = add nsw i32 %69, -1
store i32 %70, i32* %9
br label %28
71: ; preds = %28
%72 = load i32, i32* %14
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %85
74: ; preds = %71
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* %12
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i32 @atoi(i8* %79)
%81 = icmp ne i32 %76, %80
br i1 %81, label %82, label %84
82: ; preds = %74
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %84
84: ; preds = %82, %74
br label %87
85: ; preds = %71
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %85, %84
store i32 0, i32* %3
br label %88
88: ; preds = %87, %48, %42, %36, %17
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [44 x i8] c"convert -crop %ux%u+%u+0 font.png rusk.png\0A\00"
@str = [40 x i8] c"Are you sure this is a font width file?\00"
@str.5 = [4 x i8] c" };\00"
@str.6 = [34 x i8] c"Not sure if this image is correct\00"
@str.7 = [94 x i8] c"You need to specify the image width and height (oh, and provide a 24 bit RGB image on stdin).\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %51
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp eq i32 %7, 0
br i1 %11, label %51, label %12
12: ; preds = %4, %38
%13 = phi i32 [ %41, %38 ], [ 0, %4 ]
%14 = phi i32 [ %40, %38 ], [ 0, %4 ]
%15 = phi i32 [ %39, %38 ], [ 0, %4 ]
%16 = phi i32 [ %42, %38 ], [ %7, %4 ]
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %55, label %20
20: ; preds = %12
%21 = tail call i32 (...) @getchar()
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %55, label %24
24: ; preds = %20
%25 = tail call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %55, label %28
28: ; preds = %24
%29 = add nsw i32 %15, 1
%30 = icmp eq i32 %17, 255
%31 = icmp eq i32 %21, 255
%32 = and i1 %30, %31
%33 = icmp eq i32 %25, 255
%34 = and i1 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %10, i32 %14)
%37 = add nsw i32 %14, %29
br label %38
38: ; preds = %35, %28
%39 = phi i32 [ 0, %35 ], [ %29, %28 ]
%40 = phi i32 [ %37, %35 ], [ %14, %28 ]
%41 = phi i32 [ 1, %35 ], [ %13, %28 ]
%42 = add nsw i32 %16, -1
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %12
44: ; preds = %38
%45 = icmp eq i32 %41, 0
br i1 %45, label %51, label %46
46: ; preds = %44
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
%48 = load i8*, i8** %5
%49 = tail call i32 @atoi(i8* %48)
%50 = icmp eq i32 %40, %49
br i1 %50, label %55, label %51
51: ; preds = %44, %4, %46, %2
%52 = phi i8* [ getelementptr inbounds ([94 x i8], [94 x i8]* @str.7, i64 0, i64 0), %2 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0), %46 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0), %44 ]
%53 = phi i32 [ 1, %2 ], [ 0, %46 ], [ 0, %4 ], [ 0, %44 ]
%54 = tail call i32 @puts(i8* dereferenceable(1) %52)
br label %55
55: ; preds = %24, %20, %12, %51, %46
%56 = phi i32 [ 0, %46 ], [ %53, %51 ], [ 1, %24 ], [ 1, %20 ], [ 0, %12 ]
ret i32 %56
}