#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 kmod_module {
  int dummy;
};
struct kmod_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int kmod_module_new_from_path(struct kmod_ctx *, char const *,
                              struct kmod_module **);
int /*<<< orphan*/ kmod_module_unref(struct kmod_module *);
int modinfo_do(struct kmod_module *);
int /*<<< orphan*/ stderr;
int modinfo_path_do(struct kmod_ctx *ctx, const char *path) {
  struct kmod_module *mod;
  int err = kmod_module_new_from_path(ctx, path, &mod);
  if (err < 0) {
    fprintf(stderr,
            "ERROR: "
            "Module file %s not found.\n",
            path);
    return err;
  }
  err = modinfo_do(mod);
  kmod_module_unref(mod);
  return err;
}


x86 assembly (clang, -O0):
<modinfo_path_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <kmod_module_new_from_path@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1192 <modinfo_path_do+0x52>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <modinfo_path_do+0x6d>
mov    -0x20(%rbp),%rdi
call   1060 <modinfo_do@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <kmod_module_unref@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modinfo_path_do>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsp,%rdx
call   1050 <kmod_module_new_from_path@plt>
test   %eax,%eax
js     1169 <modinfo_path_do+0x29>
mov    (%rsp),%rdi
call   1060 <modinfo_do@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <kmod_module_unref@plt>
jmp    1183 <modinfo_path_do+0x43>
mov    %eax,%ebx
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.kmod_ctx = type { i32 }
%struct.kmod_module = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"ERROR: Module file %s not found.\0A\00"
define i32 @modinfo_path_do(%struct.kmod_ctx* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.kmod_ctx*
%5 = alloca i8*
%6 = alloca %struct.kmod_module*
%7 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %4
store i8* %1, i8** %5
%8 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%9 = load i8*, i8** %5
%10 = call i32 @kmod_module_new_from_path(%struct.kmod_ctx* %8, i8* %9, %struct.kmod_module** %6)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %7
store i32 %17, i32* %3
br label %24
18: ; preds = %2
%19 = load %struct.kmod_module*, %struct.kmod_module** %6
%20 = call i32 @modinfo_do(%struct.kmod_module* %19)
store i32 %20, i32* %7
%21 = load %struct.kmod_module*, %struct.kmod_module** %6
%22 = call i32 @kmod_module_unref(%struct.kmod_module* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %18, %13
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_module = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"ERROR: Module file %s not found.\0A\00"
define i32 @modinfo_path_do(%struct.kmod_ctx* %0, i8* %1) {
%3 = alloca %struct.kmod_module*
%4 = bitcast %struct.kmod_module** %3 to i8*
%5 = call i32 @kmod_module_new_from_path(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_module** %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
10: ; preds = %2
%11 = load %struct.kmod_module*, %struct.kmod_module** %3
%12 = call i32 @modinfo_do(%struct.kmod_module* %11)
%13 = load %struct.kmod_module*, %struct.kmod_module** %3
%14 = call i32 @kmod_module_unref(%struct.kmod_module* %13)
br label %15
15: ; preds = %10, %7
%16 = phi i32 [ %5, %7 ], [ %12, %10 ]
ret i32 %16
}