#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 */
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ ascii_pid;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
scalar_t__ getenv(char *);
scalar_t__ getpid();
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char const *);
char *strrchr(char *, char);
void exec_old(const char *progname, char *argv[]) {
  char *sep;
  pid_t pid;
  char ascii_pid[32];
  char pathname[strlen(argv[0]) + 1];
  char oldname[strlen(progname) + 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, progname);
  pid = getpid();
  snprintf(ascii_pid, sizeof(ascii_pid), "%lu", (unsigned long)pid);
  if (strcmp(getenv("MODULE_RECURSE") ?: "", ascii_pid) == 0) {
    fprintf(stderr, "WARNING: %s: I am not the old version!\n", oldname);
    return;
  }
  setenv("MODULE_RECURSE", ascii_pid, 1);
  execvp(oldname, argv);
  fprintf(stderr, "Kernel requires old %s, but couldn't run %s: %s\n", progname,
          oldname, strerror(errno));
  exit(2);
}


x86 assembly (clang, -O0):
<exec_old>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%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,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c7 <exec_old+0xe7>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   10c0 <memcpy@plt>
mov    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xd26(%rip),%rsi
call   10e0 <sprintf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x20,%esi
lea    0xd0b(%rip),%rdx
call   1070 <snprintf@plt>
lea    0xd03(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     132a <exec_old+0x14a>
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    133a <exec_old+0x15a>
lea    0xd12(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    133a <exec_old+0x15a>
mov    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1378 <exec_old+0x198>
mov    -0x68(%rbp),%rdx
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
lea    -0x40(%rbp),%rsi
lea    0xc8a(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <execvp@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2c1d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    %rax,%r8
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<exec_old>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%rdi
call   1060 <strlen@plt>
mov    %rsp,-0x30(%rbp)
add    $0x1,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    (%r15),%rdi
call   1060 <strlen@plt>
add    %ebx,%eax
cltq
add    $0x14,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    (%r15),%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
mov    (%r15),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     127a <exec_old+0x9a>
sub    %ebx,%eax
add    $0x1,%eax
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10c0 <memcpy@plt>
lea    0xd7f(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
call   10e0 <sprintf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd6c(%rip),%rdx
lea    -0x50(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %rax,%rcx
call   1070 <snprintf@plt>
lea    0xd55(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xd7c(%rip),%rdi
cmovne %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1305 <exec_old+0x125>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd01(%rip),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   10d0 <execvp@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%ebx
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd01(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%s%s.old\00"
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [15 x i8] c"MODULE_RECURSE\00"
@.str.3 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.4 = [40 x i8] c"WARNING: %s: I am not the old version!\0A\00"
@.str.5 = [49 x i8] c"Kernel requires old %s, but couldn't run %s: %s\0A\00"
@errno = global i32 0
define void @exec_old(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %20, %24
%26 = sext i32 %25 to i64
%27 = add i64 %26, 5
%28 = alloca i8, i64 %27
store i64 %27, i64* %10
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = call i32 @memset(i8* %18, i32 0, i32 %33)
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i8* @strrchr(i8* %37, i8 signext 47)
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %55
41: ; preds = %2
%42 = load i8**, i8*** %4
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8*, i8** %5
%46 = load i8**, i8*** %4
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = ptrtoint i8* %45 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
%52 = add nsw i64 %51, 1
%53 = trunc i64 %52 to i32
%54 = call i32 @memcpy(i8* %18, i8* %44, i32 %53)
br label %55
55: ; preds = %41, %2
%56 = load i8*, i8** %3
%57 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %56)
%58 = call i64 (...) @getpid()
store i64 %58, i64* %6
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%60 = load i64, i64* %6
%61 = call i32 @snprintf(i8* %59, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %60)
%62 = call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = inttoptr i64 %62 to i8*
br label %67
66: ; preds = %55
br label %67
67: ; preds = %66, %64
%68 = phi i8* [ %65, %64 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %66 ]
%69 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%70 = call i64 @strcmp(i8* %68, i8* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%75 = load i8*, i8** %8
ret void
76: ; preds = %67
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%78 = call i32 @setenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %77, i32 1)
%79 = load i8**, i8*** %4
%80 = call i32 @execvp(i8* %28, i8** %79)
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %3
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %82, i8* %28, i8* %84)
%86 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s%s.old\00"
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [15 x i8] c"MODULE_RECURSE\00"
@.str.3 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.4 = [40 x i8] c"WARNING: %s: I am not the old version!\0A\00"
@.str.5 = [49 x i8] c"Kernel requires old %s, but couldn't run %s: %s\0A\00"
@errno = global i32 0
define void @exec_old(i8* %0, i8** %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = tail call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i32 @strlen(i8* %0)
%12 = load i8*, i8** %1
%13 = tail call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, %11
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, 5
%17 = alloca i8, i64 %16
%18 = load i8*, i8** %1
%19 = tail call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = call i32 @memset(i8* %10, i32 0, i32 %20)
%22 = load i8*, i8** %1
%23 = call i8* @strrchr(i8* dereferenceable(1) %22, i8 signext 47)
%24 = icmp eq i8* %23, null
br i1 %24, label %32, label %25
25: ; preds = %2
%26 = ptrtoint i8* %23 to i64
%27 = ptrtoint i8* %22 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = add i32 %29, 1
%31 = call i32 @memcpy(i8* %10, i8* %22, i32 %30)
br label %32
32: ; preds = %25, %2
%33 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %0)
%34 = call i64 (...) @getpid()
%35 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %34)
%36 = call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
%38 = inttoptr i64 %36 to i8*
%39 = select i1 %37, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %38
%40 = call i64 @strcmp(i8* %39, i8* %4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %32
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %17)
ret void
45: ; preds = %32
%46 = call i32 @setenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 1)
%47 = call i32 @execvp(i8* %17, i8** %1)
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %17, i8* %50)
%52 = call i32 @exit(i32 2)
unreachable
}