#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s cmd arg\n", argv[0]);
    exit(2);
  }
  {
    char *newargv[] = {"/bin/sh", "-c", argv[1], NULL};
    execve("/bin/sh", newargv, NULL);
  }
  perror("execve");
  exit(1);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1186 <main+0x46>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
lea    0xe86(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe58(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <execve@plt>
lea    0xe53(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    1192 <main+0x52>
lea    0xec3(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xec0(%rip),%rax
mov    %rax,0x8(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <execve@plt>
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe5b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: %s cmd arg\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [7 x i8] c"execve\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %19
%23 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* null, i8** %23
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%25 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %24, i32* null)
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Usage: %s cmd arg\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [7 x i8] c"execve\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8*]
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = bitcast [4 x i8*]* %3 to i8*
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %14
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
store i8* null, i8** %17
%18 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %12, i32* null)
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
}