#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 semaphore {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ down(struct semaphore *);
void double_down(struct semaphore *s1, struct semaphore *s2) {
  if (s1 != s2) {
    if ((unsigned long)s1 < (unsigned long)s2) {
      struct semaphore *tmp = s2;
      s2 = s1;
      s1 = tmp;
    }
    down(s1);
  }
  down(s2);
}


x86 assembly (clang, -O0):
<double_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1160 <double_down+0x50>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    1157 <double_down+0x47>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <down@plt>
mov    -0x10(%rbp),%rdi
call   1030 <down@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_down>:
cmp    %rsi,%rdi
je     112a <double_down+0x1a>
push   %rbx
mov    %rsi,%rbx
cmovb  %rdi,%rbx
cmovb  %rsi,%rdi
call   1030 <down@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <down@plt>

LLVM IR (-O0):
%struct.semaphore = type { i32 }
define void @double_down(%struct.semaphore* %0, %struct.semaphore* %1) {
%3 = alloca %struct.semaphore*
%4 = alloca %struct.semaphore*
%5 = alloca %struct.semaphore*
store %struct.semaphore* %0, %struct.semaphore** %3
store %struct.semaphore* %1, %struct.semaphore** %4
%6 = load %struct.semaphore*, %struct.semaphore** %3
%7 = load %struct.semaphore*, %struct.semaphore** %4
%8 = icmp ne %struct.semaphore* %6, %7
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = load %struct.semaphore*, %struct.semaphore** %3
%11 = ptrtoint %struct.semaphore* %10 to i64
%12 = load %struct.semaphore*, %struct.semaphore** %4
%13 = ptrtoint %struct.semaphore* %12 to i64
%14 = icmp ult i64 %11, %13
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load %struct.semaphore*, %struct.semaphore** %4
store %struct.semaphore* %16, %struct.semaphore** %5
%17 = load %struct.semaphore*, %struct.semaphore** %3
store %struct.semaphore* %17, %struct.semaphore** %4
%18 = load %struct.semaphore*, %struct.semaphore** %5
store %struct.semaphore* %18, %struct.semaphore** %3
br label %19
19: ; preds = %15, %9
%20 = load %struct.semaphore*, %struct.semaphore** %3
%21 = call i32 @down(%struct.semaphore* %20)
br label %22
22: ; preds = %19, %2
%23 = load %struct.semaphore*, %struct.semaphore** %4
%24 = call i32 @down(%struct.semaphore* %23)
ret void
}

LLVM IR (-O2):
%struct.semaphore = type { i32 }
define void @double_down(%struct.semaphore* %0, %struct.semaphore* %1) {
%3 = icmp eq %struct.semaphore* %0, %1
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = icmp ult %struct.semaphore* %0, %1
%6 = select i1 %5, %struct.semaphore* %0, %struct.semaphore* %1
%7 = select i1 %5, %struct.semaphore* %1, %struct.semaphore* %0
%8 = tail call i32 @down(%struct.semaphore* %7)
br label %9
9: ; preds = %4, %2
%10 = phi %struct.semaphore* [ %6, %4 ], [ %0, %2 ]
%11 = tail call i32 @down(%struct.semaphore* %10)
ret void
}