#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;
  int d_type;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int main() {
  DIR *d;
  struct dirent *de;
  d = opendir("/home/wzz/");
  if (d == NULL) {
    printf("open dir error:%m\n");
    exit(-1);
  }
  while (de = readdir(d)) {
    printf("%s\t%d\n", de->d_name, de->d_type);
  }
  closedir(d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <main+0x42>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1197 <main+0x47>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11cf <main+0x7f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1197 <main+0x47>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11af <main+0x5f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     119d <main+0x4d>
lea    0xea2(%rip),%r14
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    1180 <main+0x30>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@.str = [11 x i8] c"/home/wzz/\00"
@.str.1 = [19 x i8] c"open dir error:%m\0A\00"
@.str.2 = [7 x i8] c"%s\09%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
store i32 0, i32* %1
%4 = call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %15, %10
%12 = load i32*, i32** %2
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %3
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %3
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
%19 = load %struct.dirent*, %struct.dirent** %3
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %21)
br label %11
23: ; preds = %11
%24 = load i32*, i32** %2
%25 = call i32 @closedir(i32* %24)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@.str = [11 x i8] c"/home/wzz/\00"
@.str.1 = [19 x i8] c"open dir error:%m\0A\00"
@.str.2 = [7 x i8] c"%s\09%d\0A\00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %18, label %9
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %3, %9
%10 = phi %struct.dirent* [ %16, %9 ], [ %4, %3 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 1
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %14)
%16 = tail call %struct.dirent* @readdir(i32* %1)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = tail call i32 @closedir(i32* %1)
ret i32 0
}