#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 */

/* Variables and functions */
int /*<<< orphan*/ W_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int checkspace(char *);
int /*<<< orphan*/ lprintf(int, char *, char *);
char *memccpy(char *, char *, char, int);
int strlen(char *);
void fax_find_directory(char *dirlist, char *directory, int size) {
  char *p, *p_help;
  p = dirlist;
  do {
    int l = strlen(p) + 1;
    if (l > size - 1)
      l = size - 1;
    p_help = memccpy(directory, p, ':', l);
    if (p_help != NULL) {
      *(p_help - 1) = '\0';
      p++;
    }
    directory[l] = '\0';
    p += strlen(directory);
    if (access(directory, W_OK) < 0) {
      lprintf(1, "fax_find_dir: can't write to '%s'", directory);
      continue;
    }
    if (checkspace(directory) > 1) {
      break;
    }
    lprintf(3, "fax_find_dir: not enough disk space in '%s'", directory);
  } while (*p != '\0');
}


x86 assembly (clang, -O0):
<fax_find_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1194 <fax_find_directory+0x44>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
mov    $0x3a,%edx
call   1060 <memccpy@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cc <fax_find_directory+0x7c>
mov    -0x28(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jge    1227 <fax_find_directory+0xd7>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xde3(%rip),%rsi
call   1070 <lprintf@plt>
jmp    1253 <fax_find_directory+0x103>
mov    -0x10(%rbp),%rdi
call   1040 <checkspace@plt>
cmp    $0x1,%eax
jle    123e <fax_find_directory+0xee>
jmp    1263 <fax_find_directory+0x113>
mov    -0x10(%rbp),%rdx
mov    $0x3,%edi
lea    0xdd4(%rip),%rsi
call   1070 <lprintf@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116b <fax_find_directory+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fax_find_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
add    $0xffffffff,%r14d
mov    0x2e79(%rip),%r12
jmp    11a0 <fax_find_directory+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
lea    0xe74(%rip),%rsi
mov    %r15,%rdx
call   1070 <lprintf@plt>
movslq %r13d,%rax
add    %rax,%rbp
cmpb   $0x0,0x0(%rbp)
je     1213 <fax_find_directory+0xc3>
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%ebx
cmp    %r14d,%eax
cmovge %r14d,%ebx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x3a,%edx
mov    %ebx,%ecx
call   1060 <memccpy@plt>
test   %rax,%rax
je     11d1 <fax_find_directory+0x81>
movb   $0x0,-0x1(%rax)
add    $0x1,%rbp
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    (%r12),%esi
mov    %r15,%rdi
call   1050 <access@plt>
test   %rax,%rax
js     1180 <fax_find_directory+0x30>
mov    %r15,%rdi
call   1040 <checkspace@plt>
cmp    $0x1,%eax
jg     1213 <fax_find_directory+0xc3>
mov    $0x3,%edi
lea    0xe14(%rip),%rsi
jmp    118c <fax_find_directory+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@W_OK = global i32 0
@.str = [34 x i8] c"fax_find_dir: can't write to '%s'\00"
@.str.1 = [44 x i8] c"fax_find_dir: not enough disk space in '%s'\00"
define void @fax_find_directory(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
br label %11
11: ; preds = %59, %3
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
%18 = icmp sgt i32 %15, %17
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %9
br label %22
22: ; preds = %19, %11
%23 = load i8*, i8** %5
%24 = load i8*, i8** %7
%25 = load i32, i32* %9
%26 = call i8* @memccpy(i8* %23, i8* %24, i8 signext 58, i32 %25)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i64 -1
store i8 0, i8* %31
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %7
br label %34
34: ; preds = %29, %22
%35 = load i8*, i8** %5
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %5
%40 = call i32 @strlen(i8* %39)
%41 = load i8*, i8** %7
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %7
%44 = load i8*, i8** %5
%45 = load i32, i32* @W_OK
%46 = call i64 @access(i8* %44, i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %34
%49 = load i8*, i8** %5
%50 = call i32 @lprintf(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %59
51: ; preds = %34
%52 = load i8*, i8** %5
%53 = call i32 @checkspace(i8* %52)
%54 = icmp sgt i32 %53, 1
br i1 %54, label %55, label %56
55: ; preds = %51
br label %64
56: ; preds = %51
%57 = load i8*, i8** %5
%58 = call i32 @lprintf(i32 3, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %48
%60 = load i8*, i8** %7
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %11, label %64
64: ; preds = %59, %55
ret void
}

LLVM IR (-O2):
@W_OK = global i32 0
@.str = [34 x i8] c"fax_find_dir: can't write to '%s'\00"
@.str.1 = [44 x i8] c"fax_find_dir: not enough disk space in '%s'\00"
define void @fax_find_directory(i8* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, -1
br label %5
5: ; preds = %33, %3
%6 = phi i8* [ %0, %3 ], [ %22, %33 ]
%7 = tail call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = icmp slt i32 %7, %4
%10 = select i1 %9, i32 %8, i32 %4
%11 = tail call i8* @memccpy(i8* %1, i8* %6, i8 signext 58, i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %11, i64 -1
store i8 0, i8* %14
%15 = getelementptr inbounds i8, i8* %6, i64 1
br label %16
16: ; preds = %13, %5
%17 = phi i8* [ %15, %13 ], [ %6, %5 ]
%18 = sext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @strlen(i8* %1)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = load i32, i32* @W_OK
%24 = tail call i64 @access(i8* %1, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = tail call i32 @lprintf(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %33
28: ; preds = %16
%29 = tail call i32 @checkspace(i8* %1)
%30 = icmp sgt i32 %29, 1
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = tail call i32 @lprintf(i32 3, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %33
33: ; preds = %26, %31
%34 = load i8, i8* %22
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %5
36: ; preds = %28, %33
ret void
}