#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_TRACEME;
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int service_attach(char *, int);
int service_run(char *svc_name, char *argv[]) {
  pid_t svc_pid;
  {
    svc_pid = fork();
    if (svc_pid == -1)
      return errno;
    if (svc_pid == 0) {
      ptrace(PTRACE_TRACEME, 0, 0, 0);
      argv++;
      execvp(argv[0], argv);
      return errno;
    }
  }
  return service_attach(svc_name, svc_pid);
}


x86 assembly (clang, -O0):
<service_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1175 <service_run+0x35>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cf <service_run+0x8f>
cmpl   $0x0,-0x1c(%rbp)
jne    11c0 <service_run+0x80>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <ptrace@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <execvp@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cf <service_run+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <service_attach@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_run>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     116b <service_run+0x2b>
cmp    $0xffffffff,%eax
je     118f <service_run+0x4f>
mov    %r14,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <service_attach@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
@PTRACE_TRACEME = global i32 0
define i32 @service_run(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* @errno
store i32 %11, i32* %3
br label %30
12: ; preds = %2
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* @PTRACE_TRACEME
%17 = call i32 @ptrace(i32 %16, i32 0, i32 0, i32 0)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = call i32 @execvp(i8* %22, i8** %23)
%25 = load i32, i32* @errno
store i32 %25, i32* %3
br label %30
26: ; preds = %12
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = call i32 @service_attach(i8* %27, i32 %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %26, %15, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@errno = global i32 0
@PTRACE_TRACEME = global i32 0
define i32 @service_run(i8* %0, i8** %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %13 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %2
%5 = load i32, i32* @errno
br label %15
6: ; preds = %2
%7 = load i32, i32* @PTRACE_TRACEME
%8 = tail call i32 @ptrace(i32 %7, i32 0, i32 0, i32 0)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @execvp(i8* %10, i8** %9)
%12 = load i32, i32* @errno
br label %15
13: ; preds = %2
%14 = tail call i32 @service_attach(i8* %0, i32 %3)
br label %15
15: ; preds = %13, %6, %4
%16 = phi i32 [ %5, %4 ], [ %12, %6 ], [ %14, %13 ]
ret i32 %16
}