#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*/ SIGSTOP;
int /*<<< orphan*/ SIGTRAP;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ execv(char const *, char *const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
scalar_t__ sc_is_debug_enabled();
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (sc_is_debug_enabled()) {
    for (int i = 0; i < argc; i++) {
      fprintf(stderr, "-%s-\n", argv[i]);
    }
  }
  if (argc < 2) {
    fprintf(stderr, "missing a command to execute");
    abort();
  }
  raise(SIGSTOP);
  printf("\n\n");
  printf("THIS OPTION IS EXPERIMENTAL\n\n");
  printf("Welcome to `snap run --gdb`.\n");
  printf("You are right before your application is execed():\n");
  printf("- set any options you may need\n");
  printf("- (optionally) set a breakpoint in 'main'\n");
  printf("- use 'cont' to start\n");
  printf("\n\n");
  raise(SIGTRAP);
  const char *executable = argv[1];
  execv(executable, (char *const *)&argv[1]);
  perror("execv failed");
  return 101;
}


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    $0x0,%al
call   1070 <sc_is_debug_enabled@plt>
cmp    $0x0,%rax
je     11e0 <main+0x70>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11db <main+0x6b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x2e>
jmp    11e0 <main+0x70>
cmpl   $0x2,-0x8(%rbp)
jge    1208 <main+0x98>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1090 <execv@plt>
lea    0xe4d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x65,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
xor    %eax,%eax
call   1070 <sc_is_debug_enabled@plt>
test   %rax,%rax
je     11cb <main+0x5b>
test   %r14d,%r14d
jle    11cb <main+0x5b>
mov    %r14d,%ebx
mov    0x2e44(%rip),%r12
lea    0xe5d(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
mov    (%r15,%rbp,8),%rdx
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11b0 <main+0x40>
cmp    $0x1,%r14d
jle    1280 <main+0x110>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
lea    0xe1a(%rip),%rbp
mov    %rbp,%rdi
call   1050 <puts@plt>
lea    0xe37(%rip),%rdi
call   1050 <puts@plt>
lea    0xe48(%rip),%rdi
call   1050 <puts@plt>
lea    0xe59(%rip),%rdi
call   1050 <puts@plt>
lea    0xe80(%rip),%rdi
call   1050 <puts@plt>
lea    0xe93(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb1(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1050 <puts@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
mov    0x8(%r15),%rdi
add    $0x8,%r15
mov    %r15,%rsi
call   1090 <execv@plt>
lea    0xdbc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x65,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [6 x i8] c"-%s-\0A\00"
@.str.1 = [29 x i8] c"missing a command to execute\00"
@SIGSTOP = global i32 0
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [30 x i8] c"THIS OPTION IS EXPERIMENTAL\0A\0A\00"
@.str.4 = [30 x i8] c"Welcome to `snap run --gdb`.\0A\00"
@.str.5 = [52 x i8] c"You are right before your application is execed():\0A\00"
@.str.6 = [32 x i8] c"- set any options you may need\0A\00"
@.str.7 = [43 x i8] c"- (optionally) set a breakpoint in 'main'\0A\00"
@.str.8 = [23 x i8] c"- use 'cont' to start\0A\00"
@SIGTRAP = global i32 0
@.str.9 = [13 x i8] c"execv failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @sc_is_debug_enabled()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %2
store i32 0, i32* %6
br label %11
11: ; preds = %23, %10
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
br label %27
27: ; preds = %26, %2
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %27
%35 = load i32, i32* @SIGSTOP
%36 = call i32 @raise(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @SIGTRAP
%46 = call i32 @raise(i32 %45)
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
store i8* %49, i8** %7
%50 = load i8*, i8** %7
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = call i32 @execv(i8* %50, i8** %52)
%54 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
ret i32 101
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [6 x i8] c"-%s-\0A\00"
@.str.1 = [29 x i8] c"missing a command to execute\00"
@SIGSTOP = global i32 0
@SIGTRAP = global i32 0
@.str.9 = [13 x i8] c"execv failed\00"
@str.10 = [29 x i8] c"THIS OPTION IS EXPERIMENTAL\0A\00"
@str.11 = [29 x i8] c"Welcome to `snap run --gdb`.\00"
@str.12 = [51 x i8] c"You are right before your application is execed():\00"
@str.13 = [31 x i8] c"- set any options you may need\00"
@str.14 = [42 x i8] c"- (optionally) set a breakpoint in 'main'\00"
@str.15 = [22 x i8] c"- use 'cont' to start\00"
@str.16 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 (...) @sc_is_debug_enabled()
%4 = icmp ne i64 %3, 0
%5 = icmp sgt i32 %0, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %15, %9 ]
%11 = load i32, i32* @stderr
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
%13 = load i8*, i8** %12
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %17, label %9
17: ; preds = %9, %2
%18 = icmp slt i32 %0, 2
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %17
%24 = load i32, i32* @SIGSTOP
%25 = tail call i32 @raise(i32 %24)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.16, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.12, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.13, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.14, i64 0, i64 0))
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.16, i64 0, i64 0))
%34 = load i32, i32* @SIGTRAP
%35 = tail call i32 @raise(i32 %34)
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = tail call i32 @execv(i8* %37, i8** %36)
%39 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
ret i32 101
}