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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int searchInDirectory(char const *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int totalOccurence = 0;
  FILE *logFile;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s string directoryname\n", argv[0]);
    return 1;
  }
  if ((logFile = fopen("log.log", "a")) == NULL) {
    fprintf(stderr, "Faield to open %s. Error: %s\n", "log.log",
            strerror(errno));
    return 1;
  }
  totalOccurence = searchInDirectory(argv[2], argv[1], logFile);
  fprintf(logFile, "%d %s were found in total.\n", totalOccurence, argv[1]);
  fclose(logFile);
  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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a2 <main+0x52>
mov    0x2e62(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1250 <main+0x100>
lea    0xe77(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1207 <main+0xb7>
mov    0x2e16(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
lea    0xe3d(%rip),%rsi
lea    0xe2c(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1250 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <searchInDirectory@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11aa <main+0x5a>
lea    0xebd(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c7 <main+0x77>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdi
mov    %rax,%rdx
call   1050 <searchInDirectory@plt>
mov    0x8(%rbx),%rcx
lea    0xeb6(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11ff <main+0xaf>
mov    0x2e2f(%rip),%rax
movslq (%rax),%rdi
mov    (%rbx),%rdx
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11fa <main+0xaa>
mov    0x2e12(%rip),%rax
movslq (%rax),%rbx
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe44(%rip),%rsi
lea    0xe33(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s string directoryname\0A\00"
@.str.1 = [8 x i8] c"log.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [30 x i8] c"Faield to open %s. Error: %s\0A\00"
@errno = global i32 0
@.str.4 = [28 x i8] c"%d %s were found in total.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %45
18: ; preds = %2
%19 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %45
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i32*, i32** %7
%36 = call i32 @searchInDirectory(i8* %31, i8* %34, i32* %35)
store i32 %36, i32* %6
%37 = load i32*, i32** %7
%38 = load i32, i32* %6
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %38, i8* %41)
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %28, %21, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s string directoryname\0A\00"
@.str.1 = [8 x i8] c"log.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [30 x i8] c"Faield to open %s. Error: %s\0A\00"
@errno = global i32 0
@.str.4 = [28 x i8] c"%d %s were found in total.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load i8*, i8** %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %29
10: ; preds = %2
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %29
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @searchInDirectory(i8* %22, i8* %24, i32* %11)
%26 = load i8*, i8** %23
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %25, i8* %26)
%28 = tail call i32 @fclose(i32* %11)
br label %29
29: ; preds = %20, %13, %4
%30 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %20 ]
ret i32 %30
}