#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*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ getenv(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setenv(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *strrchr(char *, char);
void exec_old_depmod(char *argv[]) {
  char *sep;
  char pathname[strlen(argv[0]) + 1];
  char oldname[strlen("depmod") + strlen(argv[0]) + sizeof(".old")];
  memset(pathname, 0, strlen(argv[0]) + 1);
  sep = strrchr(argv[0], '/');
  if (sep)
    memcpy(pathname, argv[0], sep - argv[0] + 1);
  sprintf(oldname, "%s%s.old", pathname, "depmod");
  if (getenv("MODULE_RECURSE"))
    return;
  setenv("MODULE_RECURSE", "y", 0);
  execvp(oldname, argv);
  fprintf(stderr, "Version requires old depmod, but couldn't run %s: %s\n",
          oldname, strerror(errno));
  exit(2);
}


x86 assembly (clang, -O0):
<exec_old_depmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe0b(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
movslq %eax,%rdx
mov    %rdx,%rax
add    $0x5,%rax
add    $0x14,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1293 <exec_old_depmod+0xe3>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rdi
lea    0xd65(%rip),%rsi
lea    0xd57(%rip),%rcx
call   10b0 <sprintf@plt>
lea    0xd5b(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12d0 <exec_old_depmod+0x120>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
lea    0xd39(%rip),%rdi
lea    0xd41(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <execvp@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd04(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<exec_old_depmod>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe1f(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1050 <strlen@plt>
add    %ebx,%eax
cltq
add    $0x14,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    (%r14),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    (%r14),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1241 <exec_old_depmod+0x91>
sub    %ebx,%eax
add    $0x1,%eax
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <memcpy@plt>
lea    0xdbf(%rip),%rsi
lea    0xdb1(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rdx
call   10b0 <sprintf@plt>
lea    0xdaf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1278 <exec_old_depmod+0xc8>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd91(%rip),%rdi
lea    0xd99(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <execvp@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%ebx
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd6b(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"depmod\00"
@.str.1 = [9 x i8] c"%s%s.old\00"
@.str.2 = [15 x i8] c"MODULE_RECURSE\00"
@.str.3 = [2 x i8] c"y\00"
@stderr = global i32 0
@.str.4 = [54 x i8] c"Version requires old depmod, but couldn't run %s: %s\0A\00"
@errno = global i32 0
define void @exec_old_depmod(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8** %0, i8*** %2
%7 = load i8**, i8*** %2
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i8**, i8*** %2
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %15, %19
%21 = sext i32 %20 to i64
%22 = add i64 %21, 5
%23 = alloca i8, i64 %22
store i64 %22, i64* %6
%24 = load i8**, i8*** %2
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = call i32 @memset(i8* %14, i32 0, i32 %28)
%30 = load i8**, i8*** %2
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i8* @strrchr(i8* %32, i8 signext 47)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %50
36: ; preds = %1
%37 = load i8**, i8*** %2
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i8*, i8** %3
%41 = load i8**, i8*** %2
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = ptrtoint i8* %40 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = add nsw i64 %46, 1
%48 = trunc i64 %47 to i32
%49 = call i32 @memcpy(i8* %14, i8* %39, i32 %48)
br label %50
50: ; preds = %36, %1
%51 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%52 = call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = load i8*, i8** %4
ret void
56: ; preds = %50
%57 = call i32 @setenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 0)
%58 = load i8**, i8*** %2
%59 = call i32 @execvp(i8* %23, i8** %58)
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %23, i8* %62)
%64 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"depmod\00"
@.str.1 = [9 x i8] c"%s%s.old\00"
@.str.2 = [15 x i8] c"MODULE_RECURSE\00"
@.str.3 = [2 x i8] c"y\00"
@stderr = global i32 0
@.str.4 = [54 x i8] c"Version requires old depmod, but couldn't run %s: %s\0A\00"
@errno = global i32 0
define void @exec_old_depmod(i8** %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @strlen(i8* %2)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %0
%9 = tail call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, %7
%11 = sext i32 %10 to i64
%12 = add nsw i64 %11, 5
%13 = alloca i8, i64 %12
%14 = load i8*, i8** %0
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = call i32 @memset(i8* %6, i32 0, i32 %16)
%18 = load i8*, i8** %0
%19 = call i8* @strrchr(i8* dereferenceable(1) %18, i8 signext 47)
%20 = icmp eq i8* %19, null
br i1 %20, label %28, label %21
21: ; preds = %1
%22 = ptrtoint i8* %19 to i64
%23 = ptrtoint i8* %18 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
%26 = add i32 %25, 1
%27 = call i32 @memcpy(i8* %6, i8* %18, i32 %26)
br label %28
28: ; preds = %21, %1
%29 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%30 = call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
ret void
33: ; preds = %28
%34 = call i32 @setenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 0)
%35 = call i32 @execvp(i8* %13, i8** %0)
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* %38)
%40 = call i32 @exit(i32 2)
unreachable
}