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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
char *get_line_from_file(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int strlen(char *);
char *strstr(int /*<<< orphan*/, char *);
char *get_line(char *id, char *filesuffix) {
  char *ret = NULL;
  DIR *d;
  struct dirent *dir;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      char *needleptr = NULL;
      if ((needleptr = strstr(dir->d_name, filesuffix)) == NULL) {
        continue;
      }
      if (*(needleptr + strlen(filesuffix)) != '\0') {
        continue;
      }
      FILE *tacfile = fopen(dir->d_name, "r");
      if (tacfile == NULL) {
        perror("fopen");
        continue;
      }
      ret = get_line_from_file(tacfile, id);
      if (ret != NULL)
        break;
    }
    closedir(d);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe61(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1286 <get_line+0x106>
jmp    11b8 <get_line+0x38>
mov    -0x20(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     127d <get_line+0xfd>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f9 <get_line+0x79>
jmp    11b8 <get_line+0x38>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1225 <get_line+0xa5>
jmp    11b8 <get_line+0x38>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1257 <get_line+0xd7>
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
jmp    11b8 <get_line+0x38>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <get_line_from_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1278 <get_line+0xf8>
jmp    127d <get_line+0xfd>
jmp    11b8 <get_line+0x38>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe68(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11be <get_line+0x3e>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     122a <get_line+0xaa>
mov    %rax,%rbp
lea    0xe46(%rip),%r12
jmp    11e0 <get_line+0x60>
xor    %ebp,%ebp
jmp    1234 <get_line+0xb4>
lea    0xe3b(%rip),%rdi
call   1090 <perror@plt>
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     122a <get_line+0xaa>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11d0 <get_line+0x50>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x0,0x0(%r13,%rax,1)
jne    11d0 <get_line+0x50>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c2 <get_line+0x42>
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <get_line_from_file@plt>
test   %rax,%rax
je     11d0 <get_line+0x50>
mov    %rax,%rbp
jmp    122c <get_line+0xac>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1050 <closedir@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
define i8* @get_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%10 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %56
13: ; preds = %2
br label %14
14: ; preds = %52, %43, %35, %25, %13
%15 = load i32*, i32** %6
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %7
%17 = icmp ne %struct.dirent* %16, null
br i1 %17, label %18, label %53
18: ; preds = %14
store i8* null, i8** %8
%19 = load %struct.dirent*, %struct.dirent** %7
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %4
%23 = call i8* @strstr(i32 %21, i8* %22)
store i8* %23, i8** %8
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %18
br label %14
26: ; preds = %18
%27 = load i8*, i8** %8
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %26
br label %14
36: ; preds = %26
%37 = load %struct.dirent*, %struct.dirent** %7
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32* @fopen(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %9
%41 = load i32*, i32** %9
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %14
45: ; preds = %36
%46 = load i32*, i32** %9
%47 = load i8*, i8** %3
%48 = call i8* @get_line_from_file(i32* %46, i8* %47)
store i8* %48, i8** %5
%49 = load i8*, i8** %5
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %52
51: ; preds = %45
br label %53
52: ; preds = %45
br label %14
53: ; preds = %51, %14
%54 = load i32*, i32** %6
%55 = call i32 @closedir(i32* %54)
br label %56
56: ; preds = %53, %2
%57 = load i8*, i8** %5
ret i8* %57
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
define i8* @get_line(i8* %0, i8* %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 %35, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %32, label %8
8: ; preds = %5, %29
%9 = phi %struct.dirent* [ %30, %29 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i8* @strstr(i32 %11, i8* %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %29, label %14
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %1)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %14
%21 = load i32, i32* %10
%22 = tail call i32* @fopen(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %29
26: ; preds = %20
%27 = tail call i8* @get_line_from_file(i32* %22, i8* %0)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26, %24, %14, %8
%30 = tail call %struct.dirent* @readdir(i32* %3)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %32, label %8
32: ; preds = %29, %26, %5
%33 = phi i8* [ null, %5 ], [ null, %29 ], [ %27, %26 ]
%34 = tail call i32 @closedir(i32* %3)
br label %35
35: ; preds = %32, %2
%36 = phi i8* [ %33, %32 ], [ null, %2 ]
ret i8* %36
}