#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 list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int PATH_MAX;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ append(struct list *, char *);
int endswith(char const *, char *);
int /*<<< orphan*/ errno;
char *malloc(int);
int /*<<< orphan*/ *realpath(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ warning(char *, char const *, int /*<<< orphan*/);
void add_volume(struct list *cmd, const char *requested_path) {
  char path[PATH_MAX];
  int read_only = endswith(requested_path, ":ro");
  if (read_only) {
    int len = strlen(requested_path);
    ((char *)requested_path)[len - 3] = '\0';
  }
  if (realpath(requested_path, path) == NULL) {
    warning("ignored volume '%s' (%s)", requested_path, strerror(errno));
    return;
  }
  if (access(path, F_OK) == -1) {
    warning("ignored volume '%s' (%s)", requested_path, strerror(errno));
    return;
  }
  char *arg = malloc(strlen(path) * 2 + 5);
  sprintf(arg, "%s:%s%s", path, path, (read_only ? ":ro" : ""));
  append(cmd, "-v");
  append(cmd, arg);
}


x86 assembly (clang, -O0):
<add_volume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1050 <endswith@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1206 <add_volume+0x76>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1070 <realpath@plt>
cmp    $0x0,%rax
jne    1251 <add_volume+0xc1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xdc4(%rip),%rdi
call   1040 <warning@plt>
movl   $0x1,-0x2c(%rbp)
jmp    130d <add_volume+0x17d>
mov    -0x40(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    12a0 <add_volume+0x110>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xd75(%rip),%rdi
call   1040 <warning@plt>
movl   $0x1,-0x2c(%rbp)
jmp    130d <add_volume+0x17d>
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x5,%edi
call   1080 <malloc@plt>
mov    -0x40(%rbp),%rcx
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd50(%rip),%r8
lea    0xd2d(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r8
lea    0xd3c(%rip),%rsi
mov    %rcx,%rdx
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   1030 <append@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <append@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_volume>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe3b(%rip),%r12
mov    %rsi,%rdi
mov    %r12,%rsi
call   1050 <endswith@plt>
mov    %eax,%r13d
test   %eax,%eax
je     11e7 <add_volume+0x57>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x3(%rax,%r15,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <realpath@plt>
test   %rax,%rax
je     1265 <add_volume+0xd5>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     1265 <add_volume+0xd5>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x5,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %r13d,%r13d
lea    0xdef(%rip),%rax
cmove  %rax,%r12
lea    0xde5(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   10a0 <sprintf@plt>
lea    0xdd5(%rip),%rsi
mov    %r14,%rdi
call   1030 <append@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <append@plt>
jmp    1284 <add_volume+0xf4>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd8a(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <warning@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.list = type { i32 }
@PATH_MAX = global i32 0
@.str = [4 x i8] c":ro\00"
@.str.1 = [25 x i8] c"ignored volume '%s' (%s)\00"
@errno = global i32 0
@F_OK = global i32 0
@.str.2 = [8 x i8] c"%s:%s%s\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"-v\00"
define void @add_volume(%struct.list* %0, i8* %1) {
%3 = alloca %struct.list*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store %struct.list* %0, %struct.list** %3
store i8* %1, i8** %4
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i8, i64 %12
store i64 %12, i64* %6
%15 = load i8*, i8** %4
%16 = call i32 @endswith(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %8
%22 = load i8*, i8** %4
%23 = load i32, i32* %8
%24 = sub nsw i32 %23, 3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %19, %2
%28 = load i8*, i8** %4
%29 = call i32* @realpath(i8* %28, i8* %14)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 @warning(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %34)
store i32 1, i32* %9
br label %61
36: ; preds = %27
%37 = load i32, i32* @F_OK
%38 = call i32 @access(i8* %14, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8*, i8** %4
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 @warning(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32 %43)
store i32 1, i32* %9
br label %61
45: ; preds = %36
%46 = call i32 @strlen(i8* %14)
%47 = mul nsw i32 %46, 2
%48 = add nsw i32 %47, 5
%49 = call i8* @malloc(i32 %48)
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%55 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* %14, i8* %54)
%56 = load %struct.list*, %struct.list** %3
%57 = call i32 @append(%struct.list* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%58 = load %struct.list*, %struct.list** %3
%59 = load i8*, i8** %10
%60 = call i32 @append(%struct.list* %58, i8* %59)
store i32 0, i32* %9
br label %61
61: ; preds = %45, %40, %31
%62 = load i8*, i8** %5
%63 = load i32, i32* %9
switch i32 %63, label %65 [
i32 0, label %64
i32 1, label %64
]
64: ; preds = %61, %61
ret void
65: ; preds = %61
unreachable
}

LLVM IR (-O2):
%struct.list = type { i32 }
@PATH_MAX = global i32 0
@.str = [4 x i8] c":ro\00"
@.str.1 = [25 x i8] c"ignored volume '%s' (%s)\00"
@errno = global i32 0
@F_OK = global i32 0
@.str.2 = [8 x i8] c"%s:%s%s\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"-v\00"
define void @add_volume(%struct.list* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 @endswith(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %1)
%10 = add nsw i32 %9, -3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %8, %2
%14 = call i32* @realpath(i8* %1, i8* %5)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @warning(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %18)
br label %37
20: ; preds = %13
%21 = load i32, i32* @F_OK
%22 = call i32 @access(i8* %5, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @warning(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %26)
br label %37
28: ; preds = %20
%29 = call i32 @strlen(i8* %5)
%30 = shl nsw i32 %29, 1
%31 = add nsw i32 %30, 5
%32 = call i8* @malloc(i32 %31)
%33 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)
%34 = call i32 @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %5, i8* %33)
%35 = call i32 @append(%struct.list* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @append(%struct.list* %0, i8* %32)
br label %37
37: ; preds = %28, %24, %16
ret void
}