#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 */
struct dirent {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  DIR *dir;
  struct dirent *dirpnt;
  FILE *file1, *file2;
  char readline[255], delimiter[] = " ";
  bool readable = true;
  if ((dir = opendir("/home/johannes/C/Parser/Logfiles")) == NULL) {
    fprintf(stderr, "Fehler beim öffnen\n");
    exit(1);
  }
  while ((dirpnt = readdir(dir)) != NULL) {
    if (file1 == NULL) {
      printf("Keine Logfiles vorhanden\n");
      exit(1);
    }
    while (fgets(readline, 255, file1)) {
      fputs(readline, stdout);
      printf("%s\n", readline);
      if (!readable) {
        file2 = fopen("/home/johannes/C/Parser/unreadable/test.txt", "w");
      }
    }
  }
  if (closedir(dir) == -1) {
    printf("Fehler beim Schließen\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0x132(%rbp)
movl   $0x1,-0x138(%rbp)
lea    0xe41(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f3 <main+0x63>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    11f8 <main+0x68>
mov    -0x10(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12ae <main+0x11e>
cmpq   $0x0,-0x20(%rbp)
jne    1232 <main+0xa2>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1237 <main+0xa7>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12a9 <main+0x119>
lea    -0x130(%rbp),%rdi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
lea    -0x130(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x138(%rbp)
jne    12a4 <main+0x114>
lea    0xdc2(%rip),%rdi
lea    0xde7(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1237 <main+0xa7>
jmp    11f8 <main+0x68>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
cmp    $0xffffffff,%eax
jne    12ce <main+0x13e>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe6d(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     121a <main+0x9a>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     11f2 <main+0x72>
mov    %rsp,%rbx
mov    0x2e21(%rip),%r15
jmp    11d3 <main+0x53>
nopl   0x0(%rax)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x40>
mov    %r14,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
jne    11d3 <main+0x53>
mov    %r14,%rdi
call   1060 <closedir@plt>
cmp    $0xffffffff,%eax
jne    120b <main+0x8b>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@__const.main.delimiter = [2 x i8] c" \00"
@.str = [33 x i8] c"/home/johannes/C/Parser/Logfiles\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Fehler beim \C3\B6ffnen\0A\00"
@.str.2 = [26 x i8] c"Keine Logfiles vorhanden\0A\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [44 x i8] c"/home/johannes/C/Parser/unreadable/test.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [24 x i8] c"Fehler beim Schlie\C3\9Fen\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [255 x i8]
%7 = alloca [2 x i8]
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [2 x i8]* %7 to i8*
store i32 1, i32* %8
%10 = call i32* @opendir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %44, %16
%18 = load i32*, i32** %2
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %3
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %45
21: ; preds = %17
%22 = load i32*, i32** %4
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21
br label %28
28: ; preds = %43, %27
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%30 = load i32*, i32** %4
%31 = call i64 @fgets(i8* %29, i32 255, i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* @stdout
%36 = call i32 @fputs(i8* %34, i32 %35)
%37 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %33
%42 = call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %42, i32** %5
br label %43
43: ; preds = %41, %33
br label %28
44: ; preds = %28
br label %17
45: ; preds = %17
%46 = load i32*, i32** %2
%47 = call i32 @closedir(i32* %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [33 x i8] c"/home/johannes/C/Parser/Logfiles\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Fehler beim \C3\B6ffnen\0A\00"
@stdout = global i32 0
@str = [23 x i8] c"Fehler beim Schlie\C3\9Fen\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %24, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %18, %15
%13 = call %struct.dirent* @readdir(i32* %3)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %24, label %15
15: ; preds = %5, %12
%16 = call i64 @fgets(i8* %2, i32 255, i32* undef)
%17 = icmp eq i64 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %15, %18
%19 = load i32, i32* @stdout
%20 = call i32 @fputs(i8* %2, i32 %19)
%21 = call i32 @puts(i8* %2)
%22 = call i64 @fgets(i8* %2, i32 255, i32* undef)
%23 = icmp eq i64 %22, 0
br i1 %23, label %12, label %18
24: ; preds = %12, %5
%25 = call i32 @closedir(i32* %3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
ret i32 0
}