#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  FILE *rfp, *wfp;
  rfp = fopen(argv[1], "r");
  wfp = fopen("./resources.lst", "w");
  char buf[100];
  if (rfp == NULL || wfp == NULL)
    perror("Error opening files");
  else {
    int row = 0;
    while (fgets(buf, 100, rfp) != NULL) {
      if (row == 0)
        fprintf(wfp, ".res R_BUILDINFO\n");
      buf[strlen(buf) - 1] = 0;
      printf("%s\n", buf);
      fprintf(wfp, ".string \"%s\" \n", buf);
      ++row;
    }
    fclose(rfp);
    fclose(wfp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ce <main+0x5e>
cmpq   $0x0,-0x20(%rbp)
jne    11df <main+0x6f>
lea    0xe3f(%rip),%rdi
call   1090 <perror@plt>
jmp    1292 <main+0x122>
movl   $0x0,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1280 <main+0x110>
cmpl   $0x0,-0x94(%rbp)
jne    1227 <main+0xb7>
mov    -0x20(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11e9 <main+0x79>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x8(%rsi),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe5b(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
test   %r14,%r14
je     12bf <main+0x13f>
mov    %rax,%r15
test   %rax,%rax
je     12bf <main+0x13f>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     129f <main+0x11f>
lea    0xe3d(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe27(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe1c(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     129f <main+0x11f>
lea    0xdef(%rip),%r12
lea    0xdec(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1260 <main+0xe0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd4e(%rip),%rdi
call   1090 <perror@plt>
jmp    12af <main+0x12f>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"./resources.lst\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [20 x i8] c"Error opening files\00"
@.str.4 = [18 x i8] c".res R_BUILDINFO\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [15 x i8] c".string \22%s\22 \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 [100 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17, %2
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %52
22: ; preds = %17
store i32 0, i32* %9
br label %23
23: ; preds = %34, %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32* @fgets(i8* %24, i32 100, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %47
28: ; preds = %23
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32*, i32** %7
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %7
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %23
47: ; preds = %23
%48 = load i32*, i32** %6
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %47, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"./resources.lst\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [20 x i8] c"Error opening files\00"
@.str.4 = [18 x i8] c".res R_BUILDINFO\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [15 x i8] c".string \22%s\22 \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = icmp eq i32* %6, null
%10 = icmp eq i32* %7, null
%11 = or i1 %9, %10
br i1 %11, label %25, label %12
12: ; preds = %2
%13 = call i32* @fgets(i8* %8, i32 100, i32* %6)
%14 = icmp eq i32* %13, null
br i1 %14, label %36, label %15
15: ; preds = %12
%16 = call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i64 17, i64 1, i32* %7)
%17 = call i32 @strlen(i8* %8)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%23 = call i32* @fgets(i8* %8, i32 100, i32* %6)
%24 = icmp eq i32* %23, null
br i1 %24, label %36, label %27
25: ; preds = %2
%26 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %39
27: ; preds = %15, %27
%28 = call i32 @strlen(i8* %8)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%34 = call i32* @fgets(i8* %8, i32 100, i32* %6)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %27
36: ; preds = %27, %15, %12
%37 = call i32 @fclose(i32* %6)
%38 = call i32 @fclose(i32* %7)
br label %39
39: ; preds = %36, %25
ret i32 0
}