#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*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ perror(char *);
size_t strlen(char *);
int main(int argc, char **argv) {
  size_t len;
  char *bin;
  len = strlen(argv[0]);
  bin = malloc(len + 1);
  memcpy(bin, argv[0], len + 1);
  if (bin[len - 1] == '1')
    bin[len - 1] = '2';
  execl(bin, bin, (char *)NULL);
  perror("execl failed");
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    11d8 <main+0x78>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x32,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
lea    0xe10(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
lea    0x1(%rax),%r12
mov    %r12,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
cmpb   $0x31,-0x1(%r14,%rbx,1)
jne    11a1 <main+0x41>
movb   $0x32,-0x1(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
lea    0xe4b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"execl failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = add i64 %12, 1
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = load i64, i64* %6
%20 = add i64 %19, 1
%21 = call i32 @memcpy(i8* %15, i8* %18, i64 %20)
%22 = load i8*, i8** %7
%23 = load i64, i64* %6
%24 = sub i64 %23, 1
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 49
br i1 %28, label %29, label %34
29: ; preds = %2
%30 = load i8*, i8** %7
%31 = load i64, i64* %6
%32 = sub i64 %31, 1
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 50, i8* %33
br label %34
34: ; preds = %29, %2
%35 = load i8*, i8** %7
%36 = load i8*, i8** %7
%37 = call i32 @execl(i8* %35, i8* %36, i8* null)
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"execl failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = add i64 %4, 1
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 @memcpy(i8* %6, i8* %3, i64 %5)
%8 = add i64 %4, -1
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 49
br i1 %11, label %12, label %13
12: ; preds = %2
store i8 50, i8* %9
br label %13
13: ; preds = %12, %2
%14 = tail call i32 @execl(i8* %6, i8* %6, i8* null)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
}