#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 libjte_env {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ libjte_report_no_mem(struct libjte_env *, scalar_t__,
                                        int /*<<< orphan*/);
int list_file_in_jigdo(struct libjte_env *, char *, int /*<<< orphan*/, char **,
                       unsigned char *);
char *strdup(char *);
scalar_t__ strlen(char *);
int libjte_decide_file_jigdo(struct libjte_env *o, char *filename, off_t size,
                             char **mirror_name, unsigned char md5[16]) {
  int ret;
  char *md5_name;
  *mirror_name = NULL;
  ret = list_file_in_jigdo(o, filename, size, &md5_name, md5);
  if (ret <= 0)
    return ret;
  *mirror_name = strdup(md5_name);
  if (*mirror_name == NULL) {
    libjte_report_no_mem(o, strlen(md5_name) + 1, 0);
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<libjte_decide_file_jigdo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%r8
lea    -0x40(%rbp),%rcx
call   1030 <list_file_in_jigdo@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     1196 <libjte_decide_file_jigdo+0x56>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <libjte_decide_file_jigdo+0xad>
mov    -0x40(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e6 <libjte_decide_file_jigdo+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
xor    %edx,%edx
call   1050 <libjte_report_no_mem@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <libjte_decide_file_jigdo+0xad>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libjte_decide_file_jigdo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdi,%r14
movq   $0x0,(%rcx)
lea    0x8(%rsp),%rcx
call   1030 <list_file_in_jigdo@plt>
test   %eax,%eax
jle    119c <libjte_decide_file_jigdo+0x5c>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
mov    $0x1,%eax
test   %rcx,%rcx
jne    119c <libjte_decide_file_jigdo+0x5c>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1050 <libjte_report_no_mem@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.libjte_env = type { i32 }
define i32 @libjte_decide_file_jigdo(%struct.libjte_env* %0, i8* %1, i32 %2, i8** %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.libjte_env*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
store %struct.libjte_env* %0, %struct.libjte_env** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8** %3, i8*** %10
store i8* %4, i8** %11
%14 = load i8**, i8*** %10
store i8* null, i8** %14
%15 = load %struct.libjte_env*, %struct.libjte_env** %7
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = load i8*, i8** %11
%19 = call i32 @list_file_in_jigdo(%struct.libjte_env* %15, i8* %16, i32 %17, i8** %13, i8* %18)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = load i32, i32* %12
store i32 %23, i32* %6
br label %38
24: ; preds = %5
%25 = load i8*, i8** %13
%26 = call i8* @strdup(i8* %25)
%27 = load i8**, i8*** %10
store i8* %26, i8** %27
%28 = load i8**, i8*** %10
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load %struct.libjte_env*, %struct.libjte_env** %7
%33 = load i8*, i8** %13
%34 = call i64 @strlen(i8* %33)
%35 = add nsw i64 %34, 1
%36 = call i32 @libjte_report_no_mem(%struct.libjte_env* %32, i64 %35, i32 0)
store i32 -1, i32* %6
br label %38
37: ; preds = %24
store i32 1, i32* %6
br label %38
38: ; preds = %37, %31, %22
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
%struct.libjte_env = type { i32 }
define i32 @libjte_decide_file_jigdo(%struct.libjte_env* %0, i8* %1, i32 %2, i8** nocapture writeonly %3, i8* %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i8* null, i8** %3
%8 = call i32 @list_file_in_jigdo(%struct.libjte_env* %0, i8* %1, i32 %2, i8** %6, i8* %4)
%9 = icmp slt i32 %8, 1
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i64 @strlen(i8* dereferenceable(1) %11)
%16 = add nsw i64 %15, 1
%17 = call i32 @libjte_report_no_mem(%struct.libjte_env* %0, i64 %16, i32 0)
br label %18
18: ; preds = %10, %5, %14
%19 = phi i32 [ -1, %14 ], [ %8, %5 ], [ 1, %10 ]
ret i32 %19
}