#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*/ chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int get_image_height(char *);
int get_image_width(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
void list_images(void) {
  char dirname[] = "img";
  DIR *imgDir = opendir(dirname);
  chdir("img");
  struct dirent *file = NULL;
  printf("Images disponibles:\n");
  while ((file = readdir(imgDir)) != NULL) {
    if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) {
      printf("%s, dimensions: %d x %d,\n", file->d_name,
             get_image_width(file->d_name), get_image_height(file->d_name));
    }
  }
  closedir(imgDir);
}


x86 assembly (clang, -O0):
<list_images>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe72(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
lea    0xe5b(%rip),%rdi
call   1050 <chdir@plt>
movq   $0x0,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1253 <list_images+0xd3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe35(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     124e <list_images+0xce>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe17(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     124e <list_images+0xce>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <get_image_width@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <get_image_height@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    11c0 <list_images+0x40>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_images>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x676d69,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <opendir@plt>
mov    %rax,%r13
lea    0xe49(%rip),%rdi
call   1060 <chdir@plt>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     124e <list_images+0xbe>
mov    %rax,%rbx
lea    0xe26(%rip),%r14
lea    0xe1e(%rip),%r15
jmp    1200 <list_images+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124e <list_images+0xbe>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     11f0 <list_images+0x60>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     11f0 <list_images+0x60>
mov    (%rbx),%rbp
mov    %rbp,%rdi
call   1050 <get_image_width@plt>
mov    %eax,%r12d
mov    (%rbx),%rdi
call   1070 <get_image_height@plt>
lea    0xdca(%rip),%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    11f0 <list_images+0x60>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@__const.list_images.dirname = [4 x i8] c"img\00"
@.str = [4 x i8] c"img\00"
@.str.1 = [21 x i8] c"Images disponibles:\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [26 x i8] c"%s, dimensions: %d x %d,\0A\00"
define void @list_images() {
%1 = alloca [4 x i8]
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = bitcast [4 x i8]* %1 to i8*
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%6 = call i32* @opendir(i8* %5)
store i32* %6, i32** %2
%7 = call i32 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.dirent* null, %struct.dirent** %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %38, %0
%10 = load i32*, i32** %2
%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 %39
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %3
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %13
%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 i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load %struct.dirent*, %struct.dirent** %3
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load %struct.dirent*, %struct.dirent** %3
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @get_image_width(i8* %31)
%33 = load %struct.dirent*, %struct.dirent** %3
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i32 @get_image_height(i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32 %32, i32 %36)
br label %38
38: ; preds = %25, %19, %13
br label %9
39: ; preds = %9
%40 = load i32*, i32** %2
%41 = call i32 @closedir(i32* %40)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [4 x i8] c"img\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [26 x i8] c"%s, dimensions: %d x %d,\0A\00"
@str = [20 x i8] c"Images disponibles:\00"
define void @list_images() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 6778217, i32* %1
%3 = call i32* @opendir(i8* %2)
%4 = tail call i32 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %27, label %8
8: ; preds = %0, %24
%9 = phi %struct.dirent* [ %25, %24 ], [ %6, %0 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = tail call i32 @get_image_width(i8* %19)
%21 = load i8*, i8** %10
%22 = tail call i32 @get_image_height(i8* %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %19, i32 %20, i32 %22)
br label %24
24: ; preds = %18, %14, %8
%25 = tail call %struct.dirent* @readdir(i32* %3)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %8
27: ; preds = %24, %0
%28 = tail call i32 @closedir(i32* %3)
ret void
}