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

/* Variables and functions */
int /*<<< orphan*/ PTRACE_SYSCALL;
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int /*<<< orphan*/ ptrace(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int wait_for_syscall(pid_t child) {
  int status;
  while (1) {
    ptrace(PTRACE_SYSCALL, child, 0, 0);
    waitpid(child, &status, 0);
    if (WIFSTOPPED(status) && WSTOPSIG(status) & 0x80)
      return 0;
    if (WIFEXITED(status))
      return 1;
  }
}


x86 assembly (clang, -O0):
<wait_for_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <ptrace@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0xc(%rbp),%edi
call   1030 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     11b2 <wait_for_syscall+0x62>
mov    -0xc(%rbp),%edi
call   1070 <WSTOPSIG@plt>
and    $0x80,%eax
cmp    $0x0,%eax
je     11b2 <wait_for_syscall+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <wait_for_syscall+0x85>
mov    -0xc(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11d0 <wait_for_syscall+0x80>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <wait_for_syscall+0x85>
jmp    115b <wait_for_syscall+0xb>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_syscall>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e76(%rip),%r15
lea    0xc(%rsp),%r14
jmp    117e <wait_for_syscall+0x2e>
nopl   0x0(%rax)
mov    0xc(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
jne    11b7 <wait_for_syscall+0x67>
mov    (%r15),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1030 <WIFSTOPPED@plt>
test   %rax,%rax
je     1170 <wait_for_syscall+0x20>
mov    0xc(%rsp),%edi
call   1070 <WSTOPSIG@plt>
test   $0x80,%al
je     1170 <wait_for_syscall+0x20>
xor    %eax,%eax
jmp    11bc <wait_for_syscall+0x6c>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PTRACE_SYSCALL = global i32 0
define i32 @wait_for_syscall(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %1, %25
%6 = load i32, i32* @PTRACE_SYSCALL
%7 = load i32, i32* %3
%8 = call i32 @ptrace(i32 %6, i32 %7, i32 0, i32 0)
%9 = load i32, i32* %3
%10 = call i32 @waitpid(i32 %9, i32* %4, i32 0)
%11 = load i32, i32* %4
%12 = call i64 @WIFSTOPPED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %5
%15 = load i32, i32* %4
%16 = call i32 @WSTOPSIG(i32 %15)
%17 = and i32 %16, 128
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %2
br label %26
20: ; preds = %14, %5
%21 = load i32, i32* %4
%22 = call i64 @WIFEXITED(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %2
br label %26
25: ; preds = %20
br label %5
26: ; preds = %24, %19
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@PTRACE_SYSCALL = global i32 0
define i32 @wait_for_syscall(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %16, %1
%5 = load i32, i32* @PTRACE_SYSCALL
%6 = call i32 @ptrace(i32 %5, i32 %0, i32 0, i32 0)
%7 = call i32 @waitpid(i32 %0, i32* %2, i32 0)
%8 = load i32, i32* %2
%9 = call i64 @WIFSTOPPED(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %4
%12 = load i32, i32* %2
%13 = call i32 @WSTOPSIG(i32 %12)
%14 = and i32 %13, 128
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11, %4
%17 = load i32, i32* %2
%18 = call i64 @WIFEXITED(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %4, label %20
20: ; preds = %16, %11
%21 = phi i32 [ 0, %11 ], [ 1, %16 ]
ret i32 %21
}