#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 PER_LINUX;
int PER_LINUX32;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ personality(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int ac, char **av) {
  int pers = (0x0008 | 0x8000000);
  if (!av[1]) {
    fprintf(stderr, "usage: %s [--3gb] [--4gb] program args ...\n", av[0]);
    fprintf(stderr, "Default is --3gb to limit the address space of the 32bit "
                    "children to 3GB\n");
    exit(1);
  }
  if (!strcmp(av[0], "linux64"))
    pers = PER_LINUX;
  else if (!strcmp(av[0], "linux32"))
    pers = (0x0008 | 0x8000000);
  if (!strcmp(av[1], "--3gb")) {
    pers = (0x0008 | 0x8000000);
    av++;
  }
  if (!strcmp(av[1], "--4gb")) {
    pers = PER_LINUX32;
    av++;
  }
  if (personality(pers) < 0) {
    fprintf(stderr, "Cannot set %x personality: %s\n", pers, strerror(errno));
    exit(1);
  }
  execvp(av[1], av + 1);
  fprintf(stderr, "Cannot execute %s: %s\n", av[1], strerror(errno));
  exit(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)
movl   $0x8000008,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11cb <main+0x6b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11f8 <main+0x98>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1220 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe78(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    121b <main+0xbb>
movl   $0x8000008,-0x14(%rbp)
jmp    1220 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1250 <main+0xf0>
movl   $0x8000008,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1285 <main+0x125>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <personality@plt>
cmp    $0x0,%rax
jge    12d8 <main+0x178>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <execvp@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
test   %rbp,%rbp
jne    11aa <main+0x4a>
mov    0x2e55(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe93(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0x8(%rbx),%r15
mov    (%rbx),%rdi
lea    0xebe(%rip),%rsi
call   1040 <strcmp@plt>
mov    $0x8000008,%r12d
mov    $0x8000008,%r14d
test   %eax,%eax
jne    11d7 <main+0x77>
mov    0x2e0c(%rip),%rax
mov    (%rax),%r14d
lea    0xea0(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
cmove  %r15,%rbx
cmove  %r12d,%r14d
mov    0x8(%rbx),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    1211 <main+0xb1>
mov    0x2dda(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   1030 <personality@plt>
test   %rax,%rax
jns    1255 <main+0xf5>
mov    0x2dab(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4e(%rip),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0x8(%rbx),%rbp
test   %r15d,%r15d
cmovne %rbx,%rbp
lea    0x8(%rbp),%rsi
mov    0x8(%rbp),%rdi
call   1060 <execvp@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rbp),%rbp
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe1a(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"usage: %s [--3gb] [--4gb] program args ...\0A\00"
@.str.1 = [74 x i8] c"Default is --3gb to limit the address space of the 32bit children to 3GB\0A\00"
@.str.2 = [8 x i8] c"linux64\00"
@PER_LINUX = global i32 0
@.str.3 = [8 x i8] c"linux32\00"
@.str.4 = [6 x i8] c"--3gb\00"
@.str.5 = [6 x i8] c"--4gb\00"
@PER_LINUX32 = global i32 0
@.str.6 = [31 x i8] c"Cannot set %x personality: %s\0A\00"
@errno = global i32 0
@.str.7 = [23 x i8] c"Cannot execute %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 134217736, i32* %6
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %20, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = load i32, i32* @PER_LINUX
store i32 %27, i32* %6
br label %36
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %28
store i32 134217736, i32* %6
br label %35
35: ; preds = %34, %28
br label %36
36: ; preds = %35, %26
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %36
store i32 134217736, i32* %6
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i32 1
store i8** %44, i8*** %5
br label %45
45: ; preds = %42, %36
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %45
%52 = load i32, i32* @PER_LINUX32
store i32 %52, i32* %6
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i32 1
store i8** %54, i8*** %5
br label %55
55: ; preds = %51, %45
%56 = load i32, i32* %6
%57 = call i64 @personality(i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i32, i32* %6
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %61, i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %55
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = call i32 @execvp(i8* %69, i8** %71)
%73 = load i32, i32* @stderr
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %76, i8* %78)
%80 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"usage: %s [--3gb] [--4gb] program args ...\0A\00"
@.str.1 = [74 x i8] c"Default is --3gb to limit the address space of the 32bit children to 3GB\0A\00"
@.str.2 = [8 x i8] c"linux64\00"
@PER_LINUX = global i32 0
@.str.4 = [6 x i8] c"--3gb\00"
@.str.5 = [6 x i8] c"--4gb\00"
@PER_LINUX32 = global i32 0
@.str.6 = [31 x i8] c"Cannot set %x personality: %s\0A\00"
@errno = global i32 0
@.str.7 = [23 x i8] c"Cannot execute %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
%17 = load i32, i32* @PER_LINUX
%18 = select i1 %16, i32 %17, i32 134217736
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8** %3, i8** %1
%22 = select i1 %20, i32 134217736, i32 %18
%23 = getelementptr inbounds i8*, i8** %21, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %24, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
%27 = load i32, i32* @PER_LINUX32
%28 = select i1 %26, i32 %27, i32 %22
%29 = tail call i64 @personality(i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %13
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %28, i8* %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %13
%38 = select i1 %26, i8** %23, i8** %21
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = tail call i32 @execvp(i8* %40, i8** %39)
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %39
%44 = load i32, i32* @errno
%45 = tail call i8* @strerror(i32 %44)
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %43, i8* %45)
%47 = tail call i32 @exit(i32 1)
unreachable
}