#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 */
scalar_t__ attach_inferior(int, char *, int *);
int /*<<< orphan*/ prepare_resume_reply(char *, char, int);
int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write_enn(char *);
int handle_v_attach(char *own_buf, char *status, int *signal) {
  int pid;
  pid = strtol(own_buf + 8, NULL, 16);
  if (pid != 0 && attach_inferior(pid, status, signal) == 0) {
    prepare_resume_reply(own_buf, *status, *signal);
    return 1;
  } else {
    write_enn(own_buf);
    return 0;
  }
}


x86 assembly (clang, -O0):
<handle_v_attach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b5 <handle_v_attach+0x75>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <attach_inferior@plt>
cmp    $0x0,%rax
jne    11b5 <handle_v_attach+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    (%rcx),%edx
movsbl %al,%esi
call   1060 <prepare_resume_reply@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <handle_v_attach+0x85>
mov    -0x10(%rbp),%rdi
call   1030 <write_enn@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_v_attach>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
add    $0x8,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
test   %eax,%eax
je     117a <handle_v_attach+0x3a>
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <attach_inferior@plt>
test   %rax,%rax
je     1184 <handle_v_attach+0x44>
mov    %rbx,%rdi
call   1030 <write_enn@plt>
jmp    119a <handle_v_attach+0x5a>
movsbl (%r12),%esi
mov    (%r15),%edx
mov    %rbx,%rdi
call   1060 <prepare_resume_reply@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @handle_v_attach(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 8
%11 = call i32 @strtol(i8* %10, i32* null, i32 16)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i32, i32* %8
%16 = load i8*, i8** %6
%17 = load i32*, i32** %7
%18 = call i64 @attach_inferior(i32 %15, i8* %16, i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = load i32*, i32** %7
%25 = load i32, i32* %24
%26 = call i32 @prepare_resume_reply(i8* %21, i8 signext %23, i32 %25)
store i32 1, i32* %4
br label %30
27: ; preds = %14, %3
%28 = load i8*, i8** %5
%29 = call i32 @write_enn(i8* %28)
store i32 0, i32* %4
br label %30
30: ; preds = %27, %20
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @handle_v_attach(i8* %0, i8* %1, i32* %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = tail call i32 @strtol(i8* nocapture %4, i32* null, i32 16)
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = tail call i64 @attach_inferior(i32 %5, i8* %1, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i8, i8* %1
%12 = load i32, i32* %2
%13 = tail call i32 @prepare_resume_reply(i8* %0, i8 signext %11, i32 %12)
br label %16
14: ; preds = %7, %3
%15 = tail call i32 @write_enn(i8* %0)
br label %16
16: ; preds = %14, %10
%17 = phi i32 [ 1, %10 ], [ 0, %14 ]
ret i32 %17
}