#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct ir_remote {
  int dummy;
};
typedef int /*<<< orphan*/ globbuf;
struct TYPE_5__ {
  int gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ lirc_parse_relative(char *, int, char *, char const *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
struct ir_remote *read_included(char const *, int, char *, struct ir_remote *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
struct ir_remote *read_all_included(const char *name, int depth, char *val,
                                    struct ir_remote *top_rem) {
  int i;
  glob_t globbuf;
  char buff[256] = {'\0'};
  memset(&globbuf, 0, sizeof(globbuf));
  val = val + 1;
  val[strlen(val) - 1] = '\0';
  lirc_parse_relative(buff, sizeof(buff), val, name);
  glob(buff, 0, NULL, &globbuf);
  for (i = 0; i < globbuf.gl_pathc; i += 1) {
    snprintf(buff, sizeof(buff), "\"%s\"", globbuf.gl_pathv[i]);
    top_rem = read_included(name, depth, buff, top_rem);
  }
  globfree(&globbuf);
  return top_rem;
}


x86 assembly (clang, -O0):
<read_all_included>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
call   1070 <lirc_parse_relative@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x38(%rbp),%rcx
call   1090 <glob@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    126f <read_all_included+0xff>
lea    -0x140(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x100,%esi
lea    0xdbf(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x140(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <read_included@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1216 <read_all_included+0xa6>
lea    -0x38(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x20(%rbp),%rax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_all_included>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x1(%r15),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,(%rax,%r15,1)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1070 <lirc_parse_relative@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r13,%rcx
call   1090 <glob@plt>
cmpl   $0x0,(%rsp)
jle    129a <read_all_included+0x12a>
xor    %ebp,%ebp
lea    0xdaa(%rip),%r15
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    (%rax,%rbp,8),%rcx
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <snprintf@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1080 <read_included@plt>
mov    %rax,%rbx
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jl     1260 <read_all_included+0xf0>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    %rbx,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ir_remote = type { i32 }
%struct.TYPE_5__ = type { i32, i8** }
@.str = [5 x i8] c"\22%s\22\00"
define %struct.ir_remote* @read_all_included(i8* %0, i32 %1, i8* %2, %struct.ir_remote* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.ir_remote*
%9 = alloca i32
%10 = alloca %struct.TYPE_5__
%11 = alloca [256 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store %struct.ir_remote* %3, %struct.ir_remote** %8
%12 = bitcast [256 x i8]* %11 to i8*
%13 = call i32 @memset(%struct.TYPE_5__* %10, i32 0, i32 16)
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = call i32 @lirc_parse_relative(i8* %22, i32 256, i8* %23, i8* %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%27 = call i32 @glob(i8* %26, i32 0, i32* null, %struct.TYPE_5__* %10)
store i32 0, i32* %9
br label %28
28: ; preds = %47, %4
%29 = load i32, i32* %9
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
%31 = load i32, i32* %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %50
33: ; preds = %28
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
%36 = load i8**, i8*** %35
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @snprintf(i8* %34, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%45 = load %struct.ir_remote*, %struct.ir_remote** %8
%46 = call %struct.ir_remote* @read_included(i8* %42, i32 %43, i8* %44, %struct.ir_remote* %45)
store %struct.ir_remote* %46, %struct.ir_remote** %8
br label %47
47: ; preds = %33
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %28
50: ; preds = %28
%51 = call i32 @globfree(%struct.TYPE_5__* %10)
%52 = load %struct.ir_remote*, %struct.ir_remote** %8
ret %struct.ir_remote* %52
}

LLVM IR (-O2):
%struct.ir_remote = type { i32 }
%struct.TYPE_5__ = type { i32, i8** }
@.str = [5 x i8] c"\22%s\22\00"
define %struct.ir_remote* @read_all_included(i8* %0, i32 %1, i8* %2, %struct.ir_remote* %3) {
%5 = alloca %struct.TYPE_5__
%6 = alloca [256 x i8]
%7 = bitcast %struct.TYPE_5__* %5 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(%struct.TYPE_5__* %5, i32 0, i32 16)
%10 = getelementptr inbounds i8, i8* %2, i64 1
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8 0, i8* %14
%15 = call i32 @lirc_parse_relative(i8* %8, i32 256, i8* %10, i8* %0)
%16 = call i32 @glob(i8* %8, i32 0, i32* null, %struct.TYPE_5__* %5)
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %4
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %30, %22 ]
%24 = phi %struct.ir_remote* [ %3, %20 ], [ %29, %22 ]
%25 = load i8**, i8*** %21
%26 = getelementptr inbounds i8*, i8** %25, i64 %23
%27 = load i8*, i8** %26
%28 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call %struct.ir_remote* @read_included(i8* %0, i32 %1, i8* %8, %struct.ir_remote* %24)
%30 = add nuw nsw i64 %23, 1
%31 = load i32, i32* %17
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %22, label %34
34: ; preds = %22, %4
%35 = phi %struct.ir_remote* [ %3, %4 ], [ %29, %22 ]
%36 = call i32 @globfree(%struct.TYPE_5__* %5)
ret %struct.ir_remote* %35
}