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

/* Variables and functions */
int O_CLOEXEC;
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *loopback_assign(char const *, int, int /*<<< orphan*/ *);
int open(char const *, int);
int /*<<< orphan*/ *opendir(char const *);
char *loopback_setup(const char *filename) {
  const char *dev_dir_path = "/dev/loop";
  int dev_dir_fd = open(dev_dir_path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
  DIR *dev_dir = opendir(dev_dir_path);
  char *loopback_device_path = loopback_assign(filename, dev_dir_fd, dev_dir);
  close(dev_dir_fd);
  closedir(dev_dir);
  return loopback_device_path;
}


x86 assembly (clang, -O0):
<loopback_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
mov    0x2e44(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1070 <loopback_assign@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loopback_setup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%r15
mov    0x2e55(%rip),%rax
or     (%rax),%esi
lea    0xe84(%rip),%r14
mov    %r14,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1070 <loopback_assign@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/loop\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
define i8* @loopback_setup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_DIRECTORY
%9 = load i32, i32* @O_RDONLY
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CLOEXEC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %7, i32 %12)
store i32 %13, i32* %4
%14 = load i8*, i8** %3
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %5
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = load i32*, i32** %5
%19 = call i8* @loopback_assign(i8* %16, i32 %17, i32* %18)
store i8* %19, i8** %6
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
%22 = load i32*, i32** %5
%23 = call i32 @closedir(i32* %22)
%24 = load i8*, i8** %6
ret i8* %24
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/loop\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
define i8* @loopback_setup(i8* %0) {
%2 = load i32, i32* @O_DIRECTORY
%3 = load i32, i32* @O_RDONLY
%4 = or i32 %3, %2
%5 = load i32, i32* @O_CLOEXEC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32* @opendir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = tail call i8* @loopback_assign(i8* %0, i32 %7, i32* %8)
%10 = tail call i32 @close(i32 %7)
%11 = tail call i32 @closedir(i32* %8)
ret i8* %9
}