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

/* Variables and functions */
char *cfg_resolve_path(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int strlen(char *);
char *cfg_find_file(char **files, char **pathes) {
  char **file, **path = pathes;
  char *options_file = NULL, *help = NULL;
  struct stat s;
  while (*path) {
    file = files;
    while (*file) {
      free(options_file);
      options_file =
          (char *)malloc(sizeof(char) * (strlen(*path) + strlen(*file) + 1));
      sprintf(options_file, "%s%s", *path, *file);
      help = cfg_resolve_path(options_file);
      if (!stat(help, &s)) {
        free(options_file);
        return help;
      }
      free(help);
      file++;
    }
    path++;
  }
  free(options_file);
  return NULL;
}


x86 assembly (clang, -O0):
<cfg_find_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     126d <cfg_find_file+0x10d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     125c <cfg_find_file+0xfc>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xdfc(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <cfg_resolve_path@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%eax
jne    1242 <cfg_find_file+0xe2>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    127e <cfg_find_file+0x11e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    119e <cfg_find_file+0x3e>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1188 <cfg_find_file+0x28>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_find_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmpq   $0x0,(%rsi)
je     1232 <cfg_find_file+0xd2>
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xe7b(%rip),%r15
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
mov    %rdi,0x8(%rsp)
jmp    11af <cfg_find_file+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpq   $0x0,0x8(%r13)
lea    0x8(%r13),%r13
je     1234 <cfg_find_file+0xd4>
cmpq   $0x0,(%r14)
je     11a0 <cfg_find_file+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%r13),%rdx
mov    (%r14),%rcx
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <cfg_resolve_path@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <stat@plt>
test   %eax,%eax
je     1236 <cfg_find_file+0xd6>
mov    %rbp,%rdi
call   1030 <free@plt>
cmpq   $0x0,0x8(%r14)
lea    0x8(%r14),%r14
jne    11c0 <cfg_find_file+0x60>
mov    0x8(%rsp),%r14
jmp    11a0 <cfg_find_file+0x40>
xor    %ebx,%ebx
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s%s\00"
define i8* @cfg_find_file(i8** %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
store i8** %0, i8*** %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
store i8** %11, i8*** %7
store i8* null, i8** %8
store i8* null, i8** %9
br label %12
12: ; preds = %58, %2
%13 = load i8**, i8*** %7
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %61
16: ; preds = %12
%17 = load i8**, i8*** %4
store i8** %17, i8*** %6
br label %18
18: ; preds = %53, %16
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %58
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = call i32 @free(i8* %23)
%25 = load i8**, i8*** %7
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %27, %30
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = load i8**, i8*** %7
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %6
%42 = load i8*, i8** %41
%43 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %40, i8* %42)
%44 = load i8*, i8** %8
%45 = call i8* @cfg_resolve_path(i8* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = call i32 @stat(i8* %46, %struct.stat* %10)
%48 = icmp ne i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %22
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %9
store i8* %52, i8** %3
br label %64
53: ; preds = %22
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
%56 = load i8**, i8*** %6
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %6
br label %18
58: ; preds = %18
%59 = load i8**, i8*** %7
%60 = getelementptr inbounds i8*, i8** %59, i32 1
store i8** %60, i8*** %7
br label %12
61: ; preds = %12
%62 = load i8*, i8** %8
%63 = call i32 @free(i8* %62)
store i8* null, i8** %3
br label %64
64: ; preds = %61, %49
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s%s\00"
define i8* @cfg_find_file(i8** nocapture %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %44, label %7
7: ; preds = %2, %39
%8 = phi i8* [ %40, %39 ], [ null, %2 ]
%9 = phi i8** [ %41, %39 ], [ %1, %2 ]
%10 = load i8*, i8** %0
%11 = icmp eq i8* %10, null
br i1 %11, label %39, label %12
12: ; preds = %7, %32
%13 = phi i8* [ %23, %32 ], [ %8, %7 ]
%14 = phi i8** [ %34, %32 ], [ %0, %7 ]
%15 = tail call i32 @free(i8* %13)
%16 = load i8*, i8** %9
%17 = tail call i32 @strlen(i8* %16)
%18 = load i8*, i8** %14
%19 = tail call i32 @strlen(i8* %18)
%20 = add i32 %17, 1
%21 = add i32 %20, %19
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i8*, i8** %9
%25 = load i8*, i8** %14
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
%27 = tail call i8* @cfg_resolve_path(i8* %23)
%28 = call i32 @stat(i8* %27, %struct.stat* %3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %12
%31 = inttoptr i64 %22 to i8*
br label %44
32: ; preds = %12
%33 = tail call i32 @free(i8* %27)
%34 = getelementptr inbounds i8*, i8** %14, i64 1
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %12
37: ; preds = %32
%38 = inttoptr i64 %22 to i8*
br label %39
39: ; preds = %37, %7
%40 = phi i8* [ %8, %7 ], [ %38, %37 ]
%41 = getelementptr inbounds i8*, i8** %9, i64 1
%42 = load i8*, i8** %41
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %7
44: ; preds = %39, %2, %30
%45 = phi i8* [ %31, %30 ], [ null, %2 ], [ %40, %39 ]
%46 = phi i8* [ %27, %30 ], [ null, %2 ], [ null, %39 ]
%47 = tail call i32 @free(i8* %45)
ret i8* %46
}