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

/* Variables and functions */
char *basename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ isspace(char);
int strlen(char *);
char *strrchr(char *, char);
int main(int argc, char **argv) {
  FILE *ifp;
  FILE *ofp;
  char buffer[1024];
  if (argc < 3)
    return 1;
  char *inFile = argv[1];
  char *outFile = argv[2];
  ifp = fopen(inFile, "r");
  if (!ifp)
    return 2;
  ofp = fopen(outFile, "w");
  if (!ofp)
    return 3;
  char *base = basename(inFile);
  *strrchr(base, '.') = '\0';
  fprintf(ofp, "const char *fallbackShader_%s =\n", base);
  while (fgets(buffer, sizeof(buffer), ifp)) {
    char *end = buffer + strlen(buffer) - 1;
    while (end >= buffer && isspace(*end))
      end--;
    end[1] = '\0';
    fprintf(ofp, "\"%s\\n\"\n", buffer);
  }
  fprintf(ofp, ";\n");
  fclose(ifp);
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11af <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x428(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x428(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fb <main+0x7b>
movl   $0x2,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x430(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1229 <main+0xa9>
movl   $0x3,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x428(%rbp),%rdi
call   1090 <basename@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x438(%rbp),%rdx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     134a <main+0x1ca>
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x448(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rcx
lea    -0x420(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x449(%rbp)
jb     12f7 <main+0x177>
mov    -0x440(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x449(%rbp)
mov    -0x449(%rbp),%al
test   $0x1,%al
jne    130a <main+0x18a>
jmp    1321 <main+0x1a1>
mov    -0x440(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x440(%rbp)
jmp    12bc <main+0x13c>
mov    -0x440(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1269 <main+0xe9>
mov    -0x20(%rbp),%rdi
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    $0x1,%eax
cmp    $0x3,%edi
jl     12e5 <main+0x155>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rbx
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0x149>
mov    %rax,%r14
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12e0 <main+0x150>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1090 <basename@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ac <main+0x11c>
lea    -0x1(%rsp),%r13
lea    0xde5(%rip),%r12
jmp    127a <main+0xea>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,0x1(%r15)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12ac <main+0x11c>
mov    %rbp,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
add    %r13,%rcx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%r15
cmp    %rbp,%rcx
jb     1250 <main+0xc0>
movsbl (%r15),%edi
call   1060 <isspace@plt>
lea    -0x1(%r15),%rcx
test   %rax,%rax
jne    1290 <main+0x100>
jmp    1250 <main+0xc0>
lea    0xd7a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12e5 <main+0x155>
mov    $0x2,%eax
jmp    12e5 <main+0x155>
mov    $0x3,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"const char *fallbackShader_%s =\0A\00"
@.str.3 = [8 x i8] c"\22%s\\n\22\0A\00"
@.str.4 = [3 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 [1024 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %81
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %9
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
store i8* %22, i8** %10
%23 = load i8*, i8** %9
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %28, label %27
27: ; preds = %16
store i32 2, i32* %3
br label %81
28: ; preds = %16
%29 = load i8*, i8** %10
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = icmp ne i32* %31, null
br i1 %32, label %34, label %33
33: ; preds = %28
store i32 3, i32* %3
br label %81
34: ; preds = %28
%35 = load i8*, i8** %9
%36 = call i8* @basename(i8* %35)
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = call i8* @strrchr(i8* %37, i8 signext 46)
store i8 0, i8* %38
%39 = load i32*, i32** %7
%40 = load i8*, i8** %11
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %68, %34
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i64 @fgets(i8* %43, i32 1024, i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %74
47: ; preds = %42
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 -1
store i8* %53, i8** %12
br label %54
54: ; preds = %65, %47
%55 = load i8*, i8** %12
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%57 = icmp uge i8* %55, %56
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i8*, i8** %12
%60 = load i8, i8* %59
%61 = call i64 @isspace(i8 signext %60)
%62 = icmp ne i64 %61, 0
br label %63
63: ; preds = %58, %54
%64 = phi i1 [ false, %54 ], [ %62, %58 ]
br i1 %64, label %65, label %68
65: ; preds = %63
%66 = load i8*, i8** %12
%67 = getelementptr inbounds i8, i8* %66, i32 -1
store i8* %67, i8** %12
br label %54
68: ; preds = %63
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8 0, i8* %70
%71 = load i32*, i32** %7
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %72)
br label %42
74: ; preds = %42
%75 = load i32*, i32** %7
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %7
%80 = call i32 @fclose(i32* %79)
store i32 0, i32* %3
br label %81
81: ; preds = %74, %33, %27, %15
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"const char *fallbackShader_%s =\0A\00"
@.str.3 = [8 x i8] c"\22%s\\n\22\0A\00"
@.str.4 = [3 x i8] c";\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %42, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %42, label %13
13: ; preds = %6
%14 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %42, label %16
16: ; preds = %13
%17 = tail call i8* @basename(i8* %8)
%18 = tail call i8* @strrchr(i8* dereferenceable(1) %17, i8 signext 46)
store i8 0, i8* %18
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%20 = call i64 @fgets(i8* %4, i32 1024, i32* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %16, %34
%23 = call i32 @strlen(i8* %4)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %24
br label %26
26: ; preds = %30, %22
%27 = phi i8* [ %25, %22 ], [ %28, %30 ]
%28 = getelementptr inbounds i8, i8* %27, i64 -1
%29 = icmp ult i8* %28, %4
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8, i8* %28
%32 = call i64 @isspace(i8 signext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %26
34: ; preds = %26, %30
store i8 0, i8* %27
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%36 = call i64 @fgets(i8* %4, i32 1024, i32* %11)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %22
38: ; preds = %34, %16
%39 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %14)
%40 = call i32 @fclose(i32* %11)
%41 = call i32 @fclose(i32* %14)
br label %42
42: ; preds = %38, %6, %13, %2
%43 = phi i32 [ 1, %2 ], [ 0, %38 ], [ 2, %6 ], [ 3, %13 ]
ret i32 %43
}