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

/* Variables and functions */
int /*<<< orphan*/ FS_CloseDir();
scalar_t__ FS_OpenDir(char *);
int FS_ReadDir(char *);
scalar_t__ strncasecmp(char *, char *, int);
int count_num_languages() {
  int num_lang = 1;
  if (FS_OpenDir("language")) {
    char filename[13];
    int type;
    while ((type = FS_ReadDir(filename)) != 0) {
      if (type == 1 && strncasecmp(filename, "lang", 4) == 0) {
        num_lang++;
      }
    }
    FS_CloseDir();
  }
  return num_lang;
}


x86 assembly (clang, -O0):
<count_num_languages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1050 <FS_OpenDir@plt>
cmp    $0x0,%rax
je     11bd <count_num_languages+0x7d>
jmp    116a <count_num_languages+0x2a>
lea    -0x11(%rbp),%rdi
call   1060 <FS_ReadDir@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11b6 <count_num_languages+0x76>
cmpl   $0x1,-0x18(%rbp)
jne    11b1 <count_num_languages+0x71>
lea    -0x11(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11b1 <count_num_languages+0x71>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116a <count_num_languages+0x2a>
mov    $0x0,%al
call   1030 <FS_CloseDir@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_num_languages>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <FS_OpenDir@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11a1 <count_num_languages+0x61>
lea    0x3(%rsp),%rbx
lea    0xe9f(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <FS_ReadDir@plt>
test   %eax,%eax
je     119a <count_num_languages+0x5a>
cmp    $0x1,%eax
jne    1170 <count_num_languages+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <strncasecmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
jmp    1170 <count_num_languages+0x30>
xor    %eax,%eax
call   1030 <FS_CloseDir@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"language\00"
@.str.1 = [5 x i8] c"lang\00"
define i32 @count_num_languages() {
%1 = alloca i32
%2 = alloca [13 x i8]
%3 = alloca i32
store i32 1, i32* %1
%4 = call i64 @FS_OpenDir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %0
br label %7
7: ; preds = %21, %6
%8 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%9 = call i32 @FS_ReadDir(i8* %8)
store i32 %9, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%16 = call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %21
21: ; preds = %18, %14, %11
br label %7
22: ; preds = %7
%23 = call i32 (...) @FS_CloseDir()
br label %24
24: ; preds = %22, %0
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"language\00"
@.str.1 = [5 x i8] c"lang\00"
define i32 @count_num_languages() {
%1 = alloca [13 x i8]
%2 = tail call i64 @FS_OpenDir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %0
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
br label %6
6: ; preds = %10, %4
%7 = phi i32 [ %14, %10 ], [ 1, %4 ]
br label %8
8: ; preds = %6, %8
%9 = call i32 @FS_ReadDir(i8* %5)
switch i32 %9, label %8 [
i32 0, label %15
i32 1, label %10
]
10: ; preds = %8
%11 = call i64 @strncasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %7, %13
br label %6
15: ; preds = %8
%16 = call i32 (...) @FS_CloseDir()
br label %17
17: ; preds = %15, %0
%18 = phi i32 [ %7, %15 ], [ 1, %0 ]
ret i32 %18
}