#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 {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  DIR *d;
  struct dirent *dir;
  FILE *fp;
  char *path = malloc(sizeof(char) * 512);
  char *filename = malloc(sizeof(char) * 512);
  if ((d = opendir("corpora")) != NULL) {
    while ((dir = readdir(d)) != NULL) {
      if (dir->d_name[0] != '.') {
        strcpy(path, "./makeStruct corpora/");
        strcpy(filename, "structs/");
        strcat(filename, dir->d_name);
        fp = fopen(filename, "r");
        if (fp == NULL) {
          strcat(path, dir->d_name);
          system(path);
        } else {
          fprintf(stderr, "Struct file '%s' already exists.\n", dir->d_name);
        }
      }
    }
    closedir(d);
  } else {
    perror("");
    return EXIT_FAILURE;
  }
  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)
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    0xe27(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12bc <main+0x11c>
jmp    11f1 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12ae <main+0x10e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     12a9 <main+0x109>
mov    -0x30(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   10c0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1288 <main+0xe8>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1050 <system@plt>
jmp    12a4 <main+0x104>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xd8a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12a9 <main+0x109>
jmp    11f1 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
jmp    12d9 <main+0x139>
lea    0xd87(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e0 <main+0x140>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe34(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12a7 <main+0x107>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     128e <main+0xee>
mov    %rax,%r12
lea    0xe26(%rip),%r13
lea    0xe28(%rip),%rbp
jmp    1239 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe05(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1080 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     128e <main+0xee>
mov    (%r12),%rax
cmpb   $0x2e,(%rax)
je     1229 <main+0x89>
mov    %r14,%rdi
lea    0xdbc(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    (%r12),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    1210 <main+0x70>
mov    (%r12),%rsi
mov    %r14,%rdi
call   10c0 <strcat@plt>
mov    %r14,%rdi
call   1050 <system@plt>
jmp    1229 <main+0x89>
mov    %r15,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9c(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
jmp    1298 <main+0xf8>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"corpora\00"
@.str.1 = [22 x i8] c"./makeStruct corpora/\00"
@.str.2 = [9 x i8] c"structs/\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [34 x i8] c"Struct file '%s' already exists.\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @malloc(i32 512)
store i8* %11, i8** %9
%12 = call i8* @malloc(i32 512)
store i8* %12, i8** %10
%13 = call i32* @opendir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %61
15: ; preds = %2
br label %16
16: ; preds = %57, %15
%17 = load i32*, i32** %6
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %7
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %58
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %7
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 46
br i1 %27, label %28, label %57
28: ; preds = %20
%29 = load i8*, i8** %9
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8*, i8** %10
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %10
%34 = load %struct.dirent*, %struct.dirent** %7
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @strcat(i8* %33, i8* %36)
%38 = load i8*, i8** %10
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %8
%40 = load i32*, i32** %8
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %50
42: ; preds = %28
%43 = load i8*, i8** %9
%44 = load %struct.dirent*, %struct.dirent** %7
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @strcat(i8* %43, i8* %46)
%48 = load i8*, i8** %9
%49 = call i32 @system(i8* %48)
br label %56
50: ; preds = %28
%51 = load i32, i32* @stderr
%52 = load %struct.dirent*, %struct.dirent** %7
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %50, %42
br label %57
57: ; preds = %56, %20
br label %16
58: ; preds = %16
%59 = load i32*, i32** %6
%60 = call i32 @closedir(i32* %59)
br label %64
61: ; preds = %2
%62 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %3
br label %65
64: ; preds = %58
store i32 0, i32* %3
br label %65
65: ; preds = %64, %61
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"corpora\00"
@.str.1 = [22 x i8] c"./makeStruct corpora/\00"
@.str.2 = [9 x i8] c"structs/\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [34 x i8] c"Struct file '%s' already exists.\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %36, label %7
7: ; preds = %2
%8 = tail call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %34, label %10
10: ; preds = %7, %31
%11 = phi %struct.dirent* [ %32, %31 ], [ %8, %7 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 46
br i1 %15, label %31, label %16
16: ; preds = %10
%17 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %12
%20 = tail call i32 @strcat(i8* %4, i8* %19)
%21 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8*, i8** %12
%25 = tail call i32 @strcat(i8* %3, i8* %24)
%26 = tail call i32 @system(i8* %3)
br label %31
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %12
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %23, %27, %10
%32 = tail call %struct.dirent* @readdir(i32* %5)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %34, label %10
34: ; preds = %31, %7
%35 = tail call i32 @closedir(i32* %5)
br label %39
36: ; preds = %2
%37 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
br label %39
39: ; preds = %34, %36
%40 = phi i32 [ 0, %34 ], [ %38, %36 ]
ret i32 %40
}