#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  FILE *out = fopen("test.bin", "w");
  int i, j, k;
  char chip;
  static char *hex =
      "\00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff";
  printf("Select chip type:\n\na for 24c01\nb for 24c02\nc for 24c04\nd for "
         "24c08\n"
         "e for 24c16\nf for 24c32\ng for 24c64\nh for 24c128\ni for 24c256\n"
         "l for 24c512\nm for 24c1024\n\nInsert a letter:");
  scanf("%c", &chip);
  getchar();
  switch (chip) {
  case 'a':
    k = 128;
    break;
  case 'b':
    k = 256;
    break;
  case 'c':
    k = 512;
    break;
  case 'd':
    k = 1024;
    break;
  case 'e':
    k = 2048;
    break;
  case 'f':
    k = 4096;
    break;
  case 'g':
    k = 8192;
    break;
  case 'h':
    k = 16384;
    break;
  case 'i':
    k = 32768;
    break;
  case 'l':
    k = 65536;
    break;
  case 'm':
    k = 131072;
    break;
  default:
    printf("Error, wrong letter\n");
    break;
  }
  for (j = 0; j < k / 16; j++) {
    for (i = 0; i < 16; i++) {
      fputc(hex[j % 16], out);
    }
  }
  fflush(out);
  fclose(out);
  printf("saved test image as test.bin\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)
lea    0xeb8(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
lea    0xf4e(%rip),%rdi
lea    -0x25(%rbp),%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
movsbl -0x25(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xc,%eax
ja     126e <main+0xfe>
mov    -0x30(%rbp),%rax
lea    0xe1f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x80,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x100,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x200,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x400,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x800,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x1000,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x2000,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x4000,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x8000,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x10000,-0x24(%rbp)
jmp    127a <main+0x10a>
movl   $0x20000,-0x24(%rbp)
jmp    127a <main+0x10a>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    12fd <main+0x18d>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    12ea <main+0x17a>
mov    0x2da1(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x40(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a6 <main+0x136>
jmp    12ef <main+0x17f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1281 <main+0x111>
mov    -0x18(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xf34(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    0xefb(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
movsbl 0xf(%rsp),%eax
lea    -0x61(%rax),%ecx
cmp    $0xd,%ecx
jae    11dd <main+0x5d>
mov    $0x19ff,%edx
bt     %ecx,%edx
jb     11ee <main+0x6e>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
jmp    12c8 <main+0x148>
cltq
lea    0xf01(%rip),%rcx
mov    -0x184(%rcx,%rax,4),%r14d
ff
xor    %r15d,%r15d
lea    0xedb(%rip),%r12
nopl   0x0(%rax)
mov    %r15d,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0x1,%r15d
cmp    %r15d,%r14d
jne    1210 <main+0x90>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.bin\00"
@.str.1 = [2 x i8] c"w\00"
@main.hex = internal global i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0)
@.str.2 = [17 x i8] c"\00\11\223DUfw\88\99\AA\BB\CC\DD\EE\FF\00"
@.str.3 = [174 x i8] c"Select chip type:\0A\0Aa for 24c01\0Ab for 24c02\0Ac for 24c04\0Ad for 24c08\0Ae for 24c16\0Af for 24c32\0Ag for 24c64\0Ah for 24c128\0Ai for 24c256\0Al for 24c512\0Am for 24c1024\0A\0AInsert a letter:\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [21 x i8] c"Error, wrong letter\0A\00"
@.str.6 = [30 x i8] c"saved test image as test.bin\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
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = call i32 @printf(i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%14 = call i32 (...) @getchar()
%15 = load i8, i8* %10
%16 = sext i8 %15 to i32
switch i32 %16, label %28 [
i32 97, label %17
i32 98, label %18
i32 99, label %19
i32 100, label %20
i32 101, label %21
i32 102, label %22
i32 103, label %23
i32 104, label %24
i32 105, label %25
i32 108, label %26
i32 109, label %27
]
17: ; preds = %2
store i32 128, i32* %9
br label %30
18: ; preds = %2
store i32 256, i32* %9
br label %30
19: ; preds = %2
store i32 512, i32* %9
br label %30
20: ; preds = %2
store i32 1024, i32* %9
br label %30
21: ; preds = %2
store i32 2048, i32* %9
br label %30
22: ; preds = %2
store i32 4096, i32* %9
br label %30
23: ; preds = %2
store i32 8192, i32* %9
br label %30
24: ; preds = %2
store i32 16384, i32* %9
br label %30
25: ; preds = %2
store i32 32768, i32* %9
br label %30
26: ; preds = %2
store i32 65536, i32* %9
br label %30
27: ; preds = %2
store i32 131072, i32* %9
br label %30
28: ; preds = %2
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17
store i32 0, i32* %8
br label %31
31: ; preds = %53, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = sdiv i32 %33, 16
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %56
36: ; preds = %31
store i32 0, i32* %7
br label %37
37: ; preds = %49, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 16
br i1 %39, label %40, label %52
40: ; preds = %37
%41 = load i8*, i8** @main.hex
%42 = load i32, i32* %8
%43 = srem i32 %42, 16
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = load i8, i8* %45
%47 = load i32*, i32** %6
%48 = call i32 @fputc(i8 signext %46, i32* %47)
br label %49
49: ; preds = %40
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %37
52: ; preds = %37
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %31
56: ; preds = %31
%57 = load i32*, i32** %6
%58 = call i32 @fflush(i32* %57)
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.bin\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"\00\11\223DUfw\88\99\AA\BB\CC\DD\EE\FF\00"
@.str.3 = [174 x i8] c"Select chip type:\0A\0Aa for 24c01\0Ab for 24c02\0Ac for 24c04\0Ad for 24c08\0Ae for 24c16\0Af for 24c32\0Ag for 24c64\0Ah for 24c128\0Ai for 24c256\0Al for 24c512\0Am for 24c1024\0A\0AInsert a letter:\00"
@.str.4 = [3 x i8] c"%c\00"
@str = [29 x i8] c"saved test image as test.bin\00"
@str.7 = [20 x i8] c"Error, wrong letter\00"
@switch.table.main = [13 x i32] [i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 8, i32 8, i32 4096, i32 8192]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([174 x i8], [174 x i8]* @.str.3, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%7 = call i32 (...) @getchar()
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = add nsw i32 %9, -97
%11 = icmp ult i32 %10, 13
br i1 %11, label %14, label %12
12: ; preds = %14, %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
br label %47
14: ; preds = %2
%15 = trunc i32 %10 to i16
%16 = lshr i16 6655, %15
%17 = and i16 %16, 1
%18 = icmp eq i16 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %14
%20 = sext i32 %10 to i64
%21 = getelementptr inbounds [13 x i32], [13 x i32]* @switch.table.main, i64 0, i64 %20
%22 = load i32, i32* %21
br label %23
23: ; preds = %19, %23
%24 = phi i32 [ %45, %23 ], [ 0, %19 ]
%25 = and i32 %24, 15
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @fputc(i8 signext %28, i32* %4)
%30 = call i32 @fputc(i8 signext %28, i32* %4)
%31 = call i32 @fputc(i8 signext %28, i32* %4)
%32 = call i32 @fputc(i8 signext %28, i32* %4)
%33 = call i32 @fputc(i8 signext %28, i32* %4)
%34 = call i32 @fputc(i8 signext %28, i32* %4)
%35 = call i32 @fputc(i8 signext %28, i32* %4)
%36 = call i32 @fputc(i8 signext %28, i32* %4)
%37 = call i32 @fputc(i8 signext %28, i32* %4)
%38 = call i32 @fputc(i8 signext %28, i32* %4)
%39 = call i32 @fputc(i8 signext %28, i32* %4)
%40 = call i32 @fputc(i8 signext %28, i32* %4)
%41 = call i32 @fputc(i8 signext %28, i32* %4)
%42 = call i32 @fputc(i8 signext %28, i32* %4)
%43 = call i32 @fputc(i8 signext %28, i32* %4)
%44 = call i32 @fputc(i8 signext %28, i32* %4)
%45 = add nuw nsw i32 %24, 1
%46 = icmp eq i32 %45, %22
br i1 %46, label %47, label %23
47: ; preds = %23, %12
%48 = call i32 @fflush(i32* %4)
%49 = call i32 @fclose(i32* %4)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i32 0
}