#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*/ execve(char *, char **, int /*<<< orphan*/ *);
int getpid();
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  argc -= optind;
  argv += optind;
  int p = getpid();
  printf("P: %d\n", getpid());
  char *st = "/usr/sbin/sshd";
  *--argv = st;
  execve(st, argv, NULL);
  printf("P: %d\n", getpid());
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffff8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x8(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execve@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    0x2ea9(%rip),%rax
mov    (%rax),%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xea9(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    (%r15,%rbx,8),%rsi
add    $0xfffffffffffffff8,%rsi
lea    0xe97(%rip),%rdi
mov    %rdi,-0x8(%r15,%rbx,8)
xor    %edx,%edx
call   1050 <execve@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@optind = global i64 0
@.str = [7 x i8] c"P: %d\0A\00"
@.str.1 = [15 x i8] c"/usr/sbin/sshd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i64, i64* @optind
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = sub nsw i64 %9, %7
%11 = trunc i64 %10 to i32
store i32 %11, i32* %3
%12 = load i64, i64* @optind
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 %12
store i8** %14, i8*** %4
%15 = call i32 (...) @getpid()
store i32 %15, i32* %5
%16 = call i32 (...) @getpid()
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16)
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %6
%18 = load i8*, i8** %6
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i32 -1
store i8** %20, i8*** %4
store i8* %18, i8** %20
%21 = load i8*, i8** %6
%22 = load i8**, i8*** %4
%23 = call i32 @execve(i8* %21, i8** %22, i32* null)
%24 = call i32 (...) @getpid()
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@optind = global i64 0
@.str = [7 x i8] c"P: %d\0A\00"
@.str.1 = [15 x i8] c"/usr/sbin/sshd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i64, i64* @optind
%4 = getelementptr inbounds i8*, i8** %1, i64 %3
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds i8*, i8** %4, i64 -1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = tail call i32 @execve(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %8, i32* null)
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}