#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process_tex_file(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(char const *, char *);
int main(int argc, char **argv) {
  const char *dirname = ".";
  const char *fname;
  DIR *dir = NULL;
  struct dirent *dirent;
  if ((dir = opendir(dirname)) == NULL) {
    printf("%s: can't open directory\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  while ((dirent = readdir(dir)) != NULL) {
    fname = dirent->d_name;
    if (strstr(fname, ".tex")) {
      fprintf(stderr, "processing %s\n", fname);
      process_tex_file(fname);
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e1 <main+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11e6 <main+0x66>
mov    -0x28(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1249 <main+0xc9>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1244 <main+0xc4>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdeb(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <process_tex_file@plt>
jmp    11e6 <main+0x66>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
lea    0xe6d(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     121d <main+0x9d>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1209 <main+0x89>
lea    0xe64(%rip),%r14
mov    0x2e21(%rip),%r13
lea    0xe5b(%rip),%r15
jmp    11dd <main+0x5d>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1209 <main+0x89>
mov    (%rax),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <process_tex_file@plt>
jmp    11d0 <main+0x50>
mov    %r12,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [26 x i8] c"%s: can't open directory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c".tex\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"processing %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
store i32* null, i32** %8
%10 = load i8*, i8** %6
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
br label %21
21: ; preds = %38, %20
%22 = load i32*, i32** %8
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %9
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load %struct.dirent*, %struct.dirent** %9
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = call i64 @strstr(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %7
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %7
%37 = call i32 @process_tex_file(i8* %36)
br label %38
38: ; preds = %32, %25
br label %21
39: ; preds = %21
%40 = load i32*, i32** %8
%41 = call i32 @closedir(i32* %40)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [26 x i8] c"%s: can't open directory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c".tex\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"processing %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %26, label %13
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %5, %23
%14 = phi %struct.dirent* [ %24, %23 ], [ %6, %5 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i64 @strstr(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%22 = tail call i32 @process_tex_file(i8* %16)
br label %23
23: ; preds = %19, %13
%24 = tail call %struct.dirent* @readdir(i32* %3)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %13
26: ; preds = %23, %5
%27 = tail call i32 @closedir(i32* %3)
ret i32 0
}