#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void mkdata(char *name) {
  FILE *fd;
  char buf[128];
  int c, len;
  sprintf(buf, "images/%s.gif", name);
  fd = fopen(buf, "r");
  if (!fd) {
    perror(buf);
    exit(-1);
  }
  printf("static const char %s_gif[] = {\n\t", name);
  len = 0;
  for (;;) {
    c = getc(fd);
    if (c < 0)
      break;
    printf("%d,", c);
    len += 2;
    if (c > 9)
      ++len;
    if (c > 99)
      ++len;
    if (len > 66) {
      printf("\n\t");
      len = 0;
    }
  }
  if (len > 0)
    printf("\n");
  printf("};\n");
}


x86 assembly (clang, -O0):
<mkdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <mkdata+0x5e>
lea    -0x90(%rbp),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jge    11fb <mkdata+0x9b>
jmp    1280 <mkdata+0x120>
mov    -0x94(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x98(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x9,-0x94(%rbp)
jle    123a <mkdata+0xda>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x63,-0x94(%rbp)
jle    1256 <mkdata+0xf6>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x42,-0x98(%rbp)
jle    127b <mkdata+0x11b>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x98(%rbp)
jmp    11da <mkdata+0x7a>
cmpl   $0x0,-0x98(%rbp)
jle    129b <mkdata+0x13b>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdata>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rbp
lea    0xe67(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1265 <mkdata+0xe5>
mov    %rax,%r12
lea    0xe47(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   10a0 <getc@plt>
test   %eax,%eax
js     124a <mkdata+0xca>
mov    %eax,%ebp
lea    0xe49(%rip),%r14
lea    0xe3f(%rip),%r15
xor    %ebx,%ebx
jmp    120e <mkdata+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   10a0 <getc@plt>
mov    %eax,%ebp
test   %eax,%eax
js     123c <mkdata+0xbc>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xa,%ebp
sbb    $0xffffffff,%ebx
cmp    $0x64,%ebp
sbb    $0xffffffff,%ebx
add    $0x2,%ebx
cmp    $0x43,%ebx
jl     1200 <mkdata+0x80>
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1200 <mkdata+0x80>
test   %ebx,%ebx
jle    124a <mkdata+0xca>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xde4(%rip),%rdi
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    %rsp,%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"images/%s.gif\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"static const char %s_gif[] = {\0A\09\00"
@.str.3 = [4 x i8] c"%d,\00"
@.str.4 = [3 x i8] c"\0A\09\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [4 x i8] c"};\0A\00"
define void @mkdata(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = call i32 @perror(i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 0, i32* %6
br label %21
21: ; preds = %48, %18
%22 = load i32*, i32** %3
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
br label %49
27: ; preds = %21
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 2
store i32 %31, i32* %6
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 9
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %27
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 99
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %43
43: ; preds = %40, %37
%44 = load i32, i32* %6
%45 = icmp sgt i32 %44, 66
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %48
48: ; preds = %46, %43
br label %21
49: ; preds = %26
%50 = load i32, i32* %6
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"images/%s.gif\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"static const char %s_gif[] = {\0A\09\00"
@.str.3 = [4 x i8] c"%d,\00"
@.str.4 = [3 x i8] c"\0A\09\00"
@str = [3 x i8] c"};\00"
define void @mkdata(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* %3)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = tail call i32 @getc(i32* %5)
%13 = icmp slt i32 %12, 0
br i1 %13, label %35, label %14
14: ; preds = %10, %27
%15 = phi i32 [ %29, %27 ], [ %12, %10 ]
%16 = phi i32 [ %28, %27 ], [ 0, %10 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%18 = icmp ugt i32 %15, 9
%19 = select i1 %18, i32 3, i32 2
%20 = add nsw i32 %19, %16
%21 = icmp ugt i32 %15, 99
%22 = zext i1 %21 to i32
%23 = add nsw i32 %20, %22
%24 = icmp sgt i32 %23, 66
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = phi i32 [ 0, %25 ], [ %23, %14 ]
%29 = tail call i32 @getc(i32* %5)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %14
31: ; preds = %27
%32 = icmp sgt i32 %28, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @putchar(i32 10)
br label %35
35: ; preds = %10, %33, %31
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}