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

/* Variables and functions */
int /*<<< orphan*/ find_txt_in_dir(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  DIR *dir = NULL;
  if (argc != 2) {
    usage();
    return 0;
  }
  char *dirname = argv[1];
  dir = opendir(dirname);
  if (dir == NULL) {
    perror("Cannot open directory.\n");
    return 0;
  }
  find_txt_in_dir(argv[1], dir);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117b <main+0x3b>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <main+0x77>
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <find_txt_in_dir@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1165 <main+0x25>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1170 <main+0x30>
mov    0x8(%rbx),%rdi
mov    %rax,%rsi
call   1030 <find_txt_in_dir@plt>
jmp    116c <main+0x2c>
xor    %eax,%eax
call   1050 <usage@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
jmp    116c <main+0x2c>

LLVM IR (-O0):
@.str = [24 x i8] c"Cannot open directory.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
store i32 0, i32* %3
br label %28
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %28
22: ; preds = %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32*, i32** %6
%27 = call i32 @find_txt_in_dir(i8* %25, i32* %26)
br label %28
28: ; preds = %22, %20, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [24 x i8] c"Cannot open directory.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %16
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @opendir(i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = tail call i32 @find_txt_in_dir(i8* %14, i32* %9)
br label %16
16: ; preds = %11, %13, %4
ret i32 0
}