#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 phi_switch(double, double, int);
int get_which4(double phi, double phiR, double phiU, double phiUR, int *LR_alt,
               int *UD_alt, int mode, double Pmax) {
  int which4;
  double dphi;
  dphi = phi - phiR;
  int LR_D = phi_switch(dphi, Pmax, mode);
  dphi = phiU - phiUR;
  int LR_U = phi_switch(dphi, Pmax, mode);
  double phi1 = phi;
  if (LR_D)
    phi1 = phiR;
  double phi2 = phiU;
  if (LR_U)
    phi2 = phiUR;
  dphi = phi1 - phi2;
  int UD = phi_switch(dphi, Pmax, mode);
  if (UD == 0) {
    if (LR_D == 0)
      which4 = 0;
    else
      which4 = 1;
  } else {
    if (LR_U == 0)
      which4 = 2;
    else
      which4 = 3;
  }
  if (mode == 0) {
    if (which4 == 0 || which4 == 1)
      *LR_alt = LR_U;
    else
      *LR_alt = LR_D;
    if (which4 == 0 || which4 == 2) {
      dphi = phiR - phiUR;
      *UD_alt = phi_switch(dphi, Pmax, mode);
    } else {
      dphi = phi - phiU;
      *UD_alt = phi_switch(dphi, Pmax, mode);
    }
  }
  return (which4);
}


x86 assembly (clang, -O0):
<get_which4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %edx,-0x34(%rbp)
movsd  %xmm4,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x34(%rbp),%edi
call   1030 <phi_switch@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x34(%rbp),%edi
call   1030 <phi_switch@plt>
mov    %eax,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     11a2 <get_which4+0x92>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cmpl   $0x0,-0x58(%rbp)
je     11c0 <get_which4+0xb0>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x34(%rbp),%edi
call   1030 <phi_switch@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jne    1210 <get_which4+0x100>
cmpl   $0x0,-0x54(%rbp)
jne    1204 <get_which4+0xf4>
movl   $0x0,-0x44(%rbp)
jmp    120b <get_which4+0xfb>
movl   $0x1,-0x44(%rbp)
jmp    1232 <get_which4+0x122>
cmpl   $0x0,-0x58(%rbp)
jne    1226 <get_which4+0x116>
movl   $0x2,-0x44(%rbp)
jmp    122d <get_which4+0x11d>
movl   $0x3,-0x44(%rbp)
jmp    1232 <get_which4+0x122>
cmpl   $0x0,-0x34(%rbp)
jne    12d7 <get_which4+0x1c7>
cmpl   $0x0,-0x44(%rbp)
je     1250 <get_which4+0x140>
cmpl   $0x1,-0x44(%rbp)
jne    125e <get_which4+0x14e>
mov    -0x58(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1267 <get_which4+0x157>
mov    -0x54(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x44(%rbp)
je     127b <get_which4+0x16b>
cmpl   $0x2,-0x44(%rbp)
jne    12a9 <get_which4+0x199>
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x34(%rbp),%edi
call   1030 <phi_switch@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    12d2 <get_which4+0x1c2>
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x34(%rbp),%edi
call   1030 <phi_switch@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
jmp    12d7 <get_which4+0x1c7>
mov    -0x44(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_which4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm4,0x10(%rsp)
mov    %edx,%ebx
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
subsd  %xmm1,%xmm0
movaps %xmm4,%xmm1
mov    %edx,%edi
call   1030 <phi_switch@plt>
mov    %eax,%r13d
movsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebx,%edi
call   1030 <phi_switch@plt>
mov    %eax,%r12d
movsd  0x20(%rsp),%xmm0
test   %r13d,%r13d
sete   %r14b
je     1188 <get_which4+0x78>
movsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
test   %r12d,%r12d
sete   %r15b
je     119c <get_which4+0x8c>
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebx,%edi
call   1030 <phi_switch@plt>
test   %eax,%eax
je     11c8 <get_which4+0xb8>
cmp    $0x1,%r12d
mov    $0x3,%ebp
sbb    $0x0,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
test   %ebx,%ebx
jne    1228 <get_which4+0x118>
jmp    11d9 <get_which4+0xc9>
xor    %eax,%eax
test   %r13d,%r13d
setne  %al
xor    %r15d,%r15d
mov    %eax,%ebp
test   %ebx,%ebx
jne    1228 <get_which4+0x118>
test   %al,%al
cmovne %r12d,%r13d
movsd  0x18(%rsp),%xmm1
subsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
test   %r15b,%r15b
jne    11ff <get_which4+0xef>
movsd  0x20(%rsp),%xmm1
subsd  0x8(%rsp),%xmm1
test   %r14b,%r14b
cmovne %r12d,%r13d
mov    0x28(%rsp),%rax
mov    %r13d,(%rax)
jne    1214 <get_which4+0x104>
movapd %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
xor    %edi,%edi
call   1030 <phi_switch@plt>
mov    0x30(%rsp),%rcx
mov    %eax,(%rcx)
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_which4(double %0, double %1, double %2, double %3, i32* %4, i32* %5, i32 %6, double %7) {
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca double
%17 = alloca i32
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca double
%22 = alloca double
%23 = alloca i32
store double %0, double* %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32 %6, i32* %15
store double %7, double* %16
%24 = load double, double* %9
%25 = load double, double* %10
%26 = fsub double %24, %25
store double %26, double* %18
%27 = load double, double* %18
%28 = load double, double* %16
%29 = load i32, i32* %15
%30 = call i32 @phi_switch(double %27, double %28, i32 %29)
store i32 %30, i32* %19
%31 = load double, double* %11
%32 = load double, double* %12
%33 = fsub double %31, %32
store double %33, double* %18
%34 = load double, double* %18
%35 = load double, double* %16
%36 = load i32, i32* %15
%37 = call i32 @phi_switch(double %34, double %35, i32 %36)
store i32 %37, i32* %20
%38 = load double, double* %9
store double %38, double* %21
%39 = load i32, i32* %19
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %8
%42 = load double, double* %10
store double %42, double* %21
br label %43
43: ; preds = %41, %8
%44 = load double, double* %11
store double %44, double* %22
%45 = load i32, i32* %20
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load double, double* %12
store double %48, double* %22
br label %49
49: ; preds = %47, %43
%50 = load double, double* %21
%51 = load double, double* %22
%52 = fsub double %50, %51
store double %52, double* %18
%53 = load double, double* %18
%54 = load double, double* %16
%55 = load i32, i32* %15
%56 = call i32 @phi_switch(double %53, double %54, i32 %55)
store i32 %56, i32* %23
%57 = load i32, i32* %23
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %49
%60 = load i32, i32* %19
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 0, i32* %17
br label %64
63: ; preds = %59
store i32 1, i32* %17
br label %64
64: ; preds = %63, %62
br label %71
65: ; preds = %49
%66 = load i32, i32* %20
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 2, i32* %17
br label %70
69: ; preds = %65
store i32 3, i32* %17
br label %70
70: ; preds = %69, %68
br label %71
71: ; preds = %70, %64
%72 = load i32, i32* %15
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %111
74: ; preds = %71
%75 = load i32, i32* %17
%76 = icmp eq i32 %75, 0
br i1 %76, label %80, label %77
77: ; preds = %74
%78 = load i32, i32* %17
%79 = icmp eq i32 %78, 1
br i1 %79, label %80, label %83
80: ; preds = %77, %74
%81 = load i32, i32* %20
%82 = load i32*, i32** %13
store i32 %81, i32* %82
br label %86
83: ; preds = %77
%84 = load i32, i32* %19
%85 = load i32*, i32** %13
store i32 %84, i32* %85
br label %86
86: ; preds = %83, %80
%87 = load i32, i32* %17
%88 = icmp eq i32 %87, 0
br i1 %88, label %92, label %89
89: ; preds = %86
%90 = load i32, i32* %17
%91 = icmp eq i32 %90, 2
br i1 %91, label %92, label %101
92: ; preds = %89, %86
%93 = load double, double* %10
%94 = load double, double* %12
%95 = fsub double %93, %94
store double %95, double* %18
%96 = load double, double* %18
%97 = load double, double* %16
%98 = load i32, i32* %15
%99 = call i32 @phi_switch(double %96, double %97, i32 %98)
%100 = load i32*, i32** %14
store i32 %99, i32* %100
br label %110
101: ; preds = %89
%102 = load double, double* %9
%103 = load double, double* %11
%104 = fsub double %102, %103
store double %104, double* %18
%105 = load double, double* %18
%106 = load double, double* %16
%107 = load i32, i32* %15
%108 = call i32 @phi_switch(double %105, double %106, i32 %107)
%109 = load i32*, i32** %14
store i32 %108, i32* %109
br label %110
110: ; preds = %101, %92
br label %111
111: ; preds = %110, %71
%112 = load i32, i32* %17
ret i32 %112
}

LLVM IR (-O2):
define i32 @get_which4(double %0, double %1, double %2, double %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32 %6, double %7) {
%9 = fsub double %0, %1
%10 = tail call i32 @phi_switch(double %9, double %7, i32 %6)
%11 = fsub double %2, %3
%12 = tail call i32 @phi_switch(double %11, double %7, i32 %6)
%13 = icmp eq i32 %10, 0
%14 = select i1 %13, double %0, double %1
%15 = icmp eq i32 %12, 0
%16 = select i1 %15, double %2, double %3
%17 = fsub double %14, %16
%18 = tail call i32 @phi_switch(double %17, double %7, i32 %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %8
%21 = xor i1 %13, true
%22 = zext i1 %21 to i32
br label %25
23: ; preds = %8
%24 = select i1 %15, i32 2, i32 3
br label %25
25: ; preds = %23, %20
%26 = phi i1 [ %13, %20 ], [ false, %23 ]
%27 = phi i1 [ %21, %20 ], [ false, %23 ]
%28 = phi i1 [ false, %20 ], [ %15, %23 ]
%29 = phi i32 [ %22, %20 ], [ %24, %23 ]
%30 = icmp eq i32 %6, 0
br i1 %30, label %31, label %39
31: ; preds = %25
%32 = or i1 %26, %27
%33 = select i1 %32, i32 %12, i32 %10
store i32 %33, i32* %4
%34 = or i1 %26, %28
%35 = fsub double %1, %3
%36 = fsub double %0, %2
%37 = select i1 %34, double %35, double %36
%38 = tail call i32 @phi_switch(double %37, double %7, i32 0)
store i32 %38, i32* %5
br label %39
39: ; preds = %31, %25
ret i32 %29
}