#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sl(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  sl("C.UTF-8");
  sl("en_US.UTF-8");
  DIR *dir = opendir("/usr/share/locale");
  if (!dir) {
    fprintf(stderr, "Can't read /usr/share/locale: %s\n", strerror(errno));
    return 1;
  }
  struct dirent *d;
  while ((d = readdir(dir)))
    sl(d->d_name);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <sl@plt>
lea    0xe96(%rip),%rdi
call   1030 <sl@plt>
lea    0xe96(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <main+0x7a>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xae>
jmp    11cf <main+0x7f>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f7 <main+0xa7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <sl@plt>
jmp    11cf <main+0x7f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1030 <sl@plt>
lea    0xea4(%rip),%rdi
call   1030 <sl@plt>
lea    0xea4(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1197 <main+0x47>
mov    %rax,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11bf <main+0x6f>
mov    (%rax),%rdi
call   1030 <sl@plt>
jmp    1180 <main+0x30>
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe71(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"C.UTF-8\00"
@.str.1 = [12 x i8] c"en_US.UTF-8\00"
@.str.2 = [18 x i8] c"/usr/share/locale\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"Can't read /usr/share/locale: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
store i32 0, i32* %1
%4 = call i32 @sl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @sl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32* @opendir(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %12)
store i32 1, i32* %1
br label %25
14: ; preds = %0
br label %15
15: ; preds = %19, %14
%16 = load i32*, i32** %2
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %3
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %3
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 @sl(i8* %22)
br label %15
24: ; preds = %15
store i32 1, i32* %1
br label %25
25: ; preds = %24, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [8 x i8] c"C.UTF-8\00"
@.str.1 = [12 x i8] c"en_US.UTF-8\00"
@.str.2 = [18 x i8] c"/usr/share/locale\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"Can't read /usr/share/locale: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = tail call i32 @sl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @sl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %20, label %13
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %11)
br label %20
13: ; preds = %5, %13
%14 = phi %struct.dirent* [ %18, %13 ], [ %6, %5 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 @sl(i8* %16)
%18 = tail call %struct.dirent* @readdir(i32* %3)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %13
20: ; preds = %13, %5, %8
ret i32 1
}