#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 */
struct mainwindow {
  int dummy;
};
typedef int pid_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ errno;
int waitpid(int, int *, int /*<<< orphan*/);
void wait_for_process(struct mainwindow *mw, int pid) {
  int status;
  pid_t ret;
  do {
    ret = waitpid(pid, &status, 0);
    if (ret == -1 && errno != EINTR)
      break;
  } while (!(ret == pid && (WIFEXITED(status) || WIFSIGNALED(status))));
}


x86 assembly (clang, -O0):
<wait_for_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1179 <wait_for_process+0x49>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
je     1179 <wait_for_process+0x49>
jmp    11ce <wait_for_process+0x9e>
jmp    117e <wait_for_process+0x4e>
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x15(%rbp)
jne    11c1 <wait_for_process+0x91>
mov    -0x10(%rbp),%edi
call   1050 <WIFEXITED@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x16(%rbp)
jne    11bb <wait_for_process+0x8b>
mov    -0x10(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    113f <wait_for_process+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_process>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0x4(%rsp),%r14
mov    0x2e9a(%rip),%r15
mov    0x2e8b(%rip),%r12
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    116a <wait_for_process+0x3a>
mov    (%r15),%rcx
cmp    (%r12),%rcx
jne    118a <wait_for_process+0x5a>
cmp    %ebx,%eax
jne    1150 <wait_for_process+0x20>
mov    0x4(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
jne    118a <wait_for_process+0x5a>
mov    0x4(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     1150 <wait_for_process+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mainwindow = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @wait_for_process(%struct.mainwindow* %0, i32 %1) {
%3 = alloca %struct.mainwindow*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.mainwindow* %0, %struct.mainwindow** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %32, %2
%8 = load i32, i32* %4
%9 = call i32 @waitpid(i32 %8, i32* %5, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
br label %35
17: ; preds = %12, %7
br label %18
18: ; preds = %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i64 @WIFEXITED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* %5
%28 = call i64 @WIFSIGNALED(i32 %27)
%29 = icmp ne i64 %28, 0
br label %30
30: ; preds = %26, %22
%31 = phi i1 [ true, %22 ], [ %29, %26 ]
br label %32
32: ; preds = %30, %18
%33 = phi i1 [ false, %18 ], [ %31, %30 ]
%34 = xor i1 %33, true
br i1 %34, label %7, label %35
35: ; preds = %32, %16
ret void
}

LLVM IR (-O2):
%struct.mainwindow = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @wait_for_process(%struct.mainwindow* nocapture readnone %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %22, %2
%6 = call i32 @waitpid(i32 %1, i32* %3, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %5, %8
%13 = icmp eq i32 %6, %1
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = load i32, i32* %3
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i64 @WIFSIGNALED(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18, %12
br label %5
23: ; preds = %14, %8, %18
ret void
}