#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  unsigned n = 0;
  int c;
  printf("unsigned char switch_image[] = {\n");
  while ((c = getchar()) != EOF) {
    printf("0x%02x,%s", c & 0xFF, (++n & 0x07) ? " " : "\n");
  }
  if (n & 0x07) {
    printf("\n");
  }
  printf("};\n"
         "int switch_size = sizeof switch_image;\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
je     119a <main+0x7a>
mov    -0xc(%rbp),%esi
and    $0xff,%esi
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
and    $0x7,%ecx
lea    0xede(%rip),%rdx
lea    0xeac(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
je     11b7 <main+0x97>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e86(%rip),%r14
cmp    (%r14),%eax
je     11b7 <main+0x77>
lea    0xe9e(%rip),%r15
lea    0xe95(%rip),%r12
lea    0xe84(%rip),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl %al,%esi
add    $0x1,%ebp
test   $0x7,%bpl
mov    %r12,%rdx
cmove  %r15,%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
jne    1180 <main+0x40>
test   $0x7,%bpl
je     11b7 <main+0x77>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"unsigned char switch_image[] = {\0A\00"
@EOF = global i32 0
@.str.1 = [10 x i8] c"0x%02x,%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [43 x i8] c"};\0Aint switch_size = sizeof switch_image;\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %9, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %3
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %5
%10 = load i32, i32* %3
%11 = and i32 %10, 255
%12 = load i32, i32* %2
%13 = add i32 %12, 1
store i32 %13, i32* %2
%14 = and i32 %13, 7
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* %17)
br label %5
19: ; preds = %5
%20 = load i32, i32* %2
%21 = and i32 %20, 7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [10 x i8] c"0x%02x,%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@str = [33 x i8] c"unsigned char switch_image[] = {\00"
@str.5 = [42 x i8] c"};\0Aint switch_size = sizeof switch_image;\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %22, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %14, %5 ], [ %2, %0 ]
%7 = phi i32 [ %9, %5 ], [ 0, %0 ]
%8 = and i32 %6, 255
%9 = add i32 %7, 1
%10 = and i32 %9, 7
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* %12)
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %5
17: ; preds = %5
%18 = and i32 %9, 7
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @putchar(i32 10)
br label %22
22: ; preds = %0, %20, %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}