#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*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  DIR *dir = opendir(argv[1]);
  struct dirent *entry;
  while ((entry = readdir(dir)) != NULL) {
    printf("\n%s ", entry->d_name);
    int i = 0;
    while (entry->d_name[i]) {
      unsigned int a = (unsigned char)entry->d_name[i++];
      printf("0x%x(%c) ", a, entry->d_name[i - 1]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ea <main+0xba>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11e5 <main+0xb5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118a <main+0x5a>
jmp    1157 <main+0x27>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x8(%rsi),%rdi
call   1030 <opendir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     11c3 <main+0x93>
mov    %rax,%r13
lea    0xea4(%rip),%r15
lea    0xea2(%rip),%r12
jmp    1180 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     11c3 <main+0x93>
mov    0x0(%r13),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%rax
mov    (%rax),%al
test   %al,%al
je     1170 <main+0x40>
mov    $0x1,%ebx
nopl   (%rax)
movzbl %al,%esi
movsbl %sil,%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%rax
movzbl (%rax,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <main+0x70>
jmp    1170 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"\0A%s \00"
@.str.1 = [10 x i8] c"0x%x(%c) \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %6
br label %14
14: ; preds = %53, %2
%15 = load i32*, i32** %6
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %7
%17 = icmp ne %struct.dirent* %16, null
br i1 %17, label %18, label %54
18: ; preds = %14
%19 = load %struct.dirent*, %struct.dirent** %7
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %8
br label %23
23: ; preds = %32, %18
%24 = load %struct.dirent*, %struct.dirent** %7
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %53
32: ; preds = %23
%33 = load %struct.dirent*, %struct.dirent** %7
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = load %struct.dirent*, %struct.dirent** %7
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %51)
br label %23
53: ; preds = %23
br label %14
54: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"\0A%s \00"
@.str.1 = [10 x i8] c"0x%x(%c) \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @opendir(i8* %4)
%6 = tail call %struct.dirent* @readdir(i32* %5)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %30, label %11
8: ; preds = %19, %11
%9 = tail call %struct.dirent* @readdir(i32* %5)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %30, label %11
11: ; preds = %2, %8
%12 = phi %struct.dirent* [ %9, %8 ], [ %6, %2 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %13
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %8, label %19
19: ; preds = %11, %19
%20 = phi i64 [ %22, %19 ], [ 0, %11 ]
%21 = phi i8 [ %28, %19 ], [ %17, %11 ]
%22 = add nuw i64 %20, 1
%23 = zext i8 %21 to i32
%24 = sext i8 %21 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i8*, i8** %13
%27 = getelementptr inbounds i8, i8* %26, i64 %22
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %8, label %19
30: ; preds = %8, %2
ret i32 0
}