#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 WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WIFSIGNALED(int);
int /*<<< orphan*/ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int test_sys_wait_macros(void) {
  int i;
  for (i = 0; i < 0x8000; i = (i ? i << 1 : 1)) {
    if (i == 0x80)
      continue;
    if (!!WIFSIGNALED(i) + !!WIFEXITED(i) + !!WIFSTOPPED(i) != 1)
      return 1;
  }
  i = WEXITSTATUS(i) + WSTOPSIG(i) + WTERMSIG(i);
  switch (i) { break; }
  return 0;
}


x86 assembly (clang, -O0):
<test_sys_wait_macros>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x8000,-0x8(%rbp)
jge    1237 <test_sys_wait_macros+0xd7>
cmpl   $0x80,-0x8(%rbp)
jne    118e <test_sys_wait_macros+0x2e>
jmp    1207 <test_sys_wait_macros+0xa7>
mov    -0x8(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <WIFSTOPPED@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
cmp    $0x1,%eax
je     1202 <test_sys_wait_macros+0xa2>
movl   $0x1,-0x4(%rbp)
jmp    126d <test_sys_wait_macros+0x10d>
jmp    1207 <test_sys_wait_macros+0xa7>
cmpl   $0x0,-0x8(%rbp)
je     121f <test_sys_wait_macros+0xbf>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122c <test_sys_wait_macros+0xcc>
mov    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122c <test_sys_wait_macros+0xcc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    116f <test_sys_wait_macros+0xf>
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <WSTOPSIG@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sys_wait_macros>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    $0x1,%r14d
jmp    1193 <test_sys_wait_macros+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
lea    (%rbx,%rbx,1),%eax
mov    %eax,%ebx
cmove  %r14d,%ebx
cmp    $0x8000,%ebx
jge    11d4 <test_sys_wait_macros+0x74>
cmp    $0x80,%ebx
je     1180 <test_sys_wait_macros+0x20>
mov    %ebx,%edi
call   1030 <WIFSIGNALED@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1070 <WIFEXITED@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
cmp    $0x1,%r15d
sbb    $0xffffffff,%ebp
mov    %ebx,%edi
call   1040 <WIFSTOPPED@plt>
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
cmp    $0x1,%ebp
je     1180 <test_sys_wait_macros+0x20>
mov    $0x1,%eax
jmp    11eb <test_sys_wait_macros+0x8b>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
mov    %ebx,%edi
call   1080 <WSTOPSIG@plt>
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_sys_wait_macros() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %41, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 32768
br i1 %5, label %6, label %43
6: ; preds = %3
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 128
br i1 %8, label %9, label %10
9: ; preds = %6
br label %34
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i32 @WIFSIGNALED(i32 %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
%15 = xor i1 %14, true
%16 = zext i1 %15 to i32
%17 = load i32, i32* %2
%18 = call i32 @WIFEXITED(i32 %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
%23 = add nsw i32 %16, %22
%24 = load i32, i32* %2
%25 = call i32 @WIFSTOPPED(i32 %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = add nsw i32 %23, %29
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %10
store i32 1, i32* %1
br label %54
33: ; preds = %10
br label %34
34: ; preds = %33, %9
%35 = load i32, i32* %2
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %2
%39 = shl i32 %38, 1
br label %41
40: ; preds = %34
br label %41
41: ; preds = %40, %37
%42 = phi i32 [ %39, %37 ], [ 1, %40 ]
store i32 %42, i32* %2
br label %3
43: ; preds = %3
%44 = load i32, i32* %2
%45 = call i32 @WEXITSTATUS(i32 %44)
%46 = load i32, i32* %2
%47 = call i32 @WSTOPSIG(i32 %46)
%48 = add nsw i32 %45, %47
%49 = load i32, i32* %2
%50 = call i32 @WTERMSIG(i32 %49)
%51 = add nsw i32 %48, %50
store i32 %51, i32* %2
%52 = load i32, i32* %2
switch i32 %52, label %53 [
]
53: ; preds = %43
store i32 0, i32* %1
br label %54
54: ; preds = %53, %32
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
define i32 @test_sys_wait_macros() {
br label %1
1: ; preds = %0, %17
%2 = phi i32 [ 0, %0 ], [ %20, %17 ]
%3 = icmp eq i32 %2, 128
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32 @WIFSIGNALED(i32 %2)
%6 = icmp ne i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @WIFEXITED(i32 %2)
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %10, %7
%12 = tail call i32 @WIFSTOPPED(i32 %2)
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %26
17: ; preds = %4, %1
%18 = icmp eq i32 %2, 0
%19 = shl i32 %2, 1
%20 = select i1 %18, i32 1, i32 %19
%21 = icmp slt i32 %20, 32768
br i1 %21, label %1, label %22
22: ; preds = %17
%23 = tail call i32 @WEXITSTATUS(i32 %20)
%24 = tail call i32 @WSTOPSIG(i32 %20)
%25 = tail call i32 @WTERMSIG(i32 %20)
br label %26
26: ; preds = %4, %22
%27 = phi i32 [ 0, %22 ], [ 1, %4 ]
ret i32 %27
}