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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
void listujPliki(const char *sciezka) {
  struct dirent *plik;
  DIR *katalog;
  if ((katalog = opendir(sciezka))) {
    while ((plik = readdir(katalog)))
      puts(plik->d_name);
    closedir(katalog);
  } else {
    printf("błąd opendir(%s)\n", sciezka);
  }
}


x86 assembly (clang, -O0):
<listujPliki>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ad <listujPliki+0x5d>
jmp    1178 <listujPliki+0x28>
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     119f <listujPliki+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <puts@plt>
jmp    1178 <listujPliki+0x28>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
jmp    11bd <listujPliki+0x6d>
mov    -0x8(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listujPliki>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     1195 <listujPliki+0x45>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1186 <listujPliki+0x36>
mov    (%rax),%edi
call   1030 <puts@plt>
jmp    1170 <listujPliki+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <closedir@plt>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [20 x i8] c"b\C5\82\C4\85d opendir(%s)\0A\00"
define void @listujPliki(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.dirent*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @opendir(i8* %5)
store i32* %6, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %21
8: ; preds = %1
br label %9
9: ; preds = %13, %8
%10 = load i32*, i32** %4
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %3
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %3
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @puts(i32 %16)
br label %9
18: ; preds = %9
%19 = load i32*, i32** %4
%20 = call i32 @closedir(i32* %19)
br label %24
21: ; preds = %1
%22 = load i8*, i8** %2
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [20 x i8] c"b\C5\82\C4\85d opendir(%s)\0A\00"
define void @listujPliki(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4, %7
%8 = phi %struct.dirent* [ %12, %7 ], [ %5, %4 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @puts(i32 %10)
%12 = tail call %struct.dirent* @readdir(i32* %2)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %14, label %7
14: ; preds = %7, %4
%15 = tail call i32 @closedir(i32* %2)
br label %18
16: ; preds = %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %14
ret void
}