#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*/ closedir(int /*<<< orphan*/ *);
scalar_t__ opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("参数错误:使用方式:main dirname.\n");
    return 0;
  }
  DIR *dp = NULL;
  struct dirent *dirp = NULL;
  dp = (DIR *)opendir(argv[1]);
  while ((dirp = readdir(dp)) != NULL) {
    printf("%s\n", dirp->d_name);
  }
  closedir(dp);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dc <main+0x9c>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cc <main+0x8c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119b <main+0x5b>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1177 <main+0x37>
mov    0x8(%rsi),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
call   1060 <readdir@plt>
test   %rax,%rax
je     1185 <main+0x45>
mov    (%rax),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
jmp    1160 <main+0x20>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
jmp    118d <main+0x4d>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [41 x i8] c"\E5\8F\82\E6\95\B0\E9\94\99\E8\AF\AF:\E4\BD\BF\E7\94\A8\E6\96\B9\E5\BC\8F:main dirname.\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %30
12: ; preds = %2
store i32* null, i32** %6
store %struct.dirent* null, %struct.dirent** %7
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @opendir(i8* %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %6
br label %18
18: ; preds = %22, %12
%19 = load i32*, i32** %6
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %7
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %7
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %18
27: ; preds = %18
%28 = load i32*, i32** %6
%29 = call i32 @closedir(i32* %28)
store i32 0, i32* %3
br label %30
30: ; preds = %27, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@str = [40 x i8] c"\E5\8F\82\E6\95\B0\E9\94\99\E8\AF\AF:\E4\BD\BF\E7\94\A8\E6\96\B9\E5\BC\8F:main dirname.\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @opendir(i8* %8)
%10 = inttoptr i64 %9 to i32*
%11 = tail call %struct.dirent* @readdir(i32* %10)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %20, label %13
13: ; preds = %6, %13
%14 = phi %struct.dirent* [ %18, %13 ], [ %11, %6 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = tail call %struct.dirent* @readdir(i32* %10)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %13
20: ; preds = %13, %6
%21 = tail call i32 @closedir(i32* %10)
br label %22
22: ; preds = %20, %4
ret i32 0
}