#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*/ semaphore_enter(struct semaphore *);
void semaphore_enter_ordered(struct semaphore *sem1, struct semaphore *sem2) {
  if (sem1 < sem2) {
    semaphore_enter(sem1);
    semaphore_enter(sem2);
  } else if (sem1 > sem2) {
    semaphore_enter(sem2);
    semaphore_enter(sem1);
  } else {
    semaphore_enter(sem1);
  }
}


x86 assembly (clang, -O0):
<semaphore_enter_ordered>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1145 <semaphore_enter_ordered+0x35>
mov    -0x8(%rbp),%rdi
call   1030 <semaphore_enter@plt>
mov    -0x10(%rbp),%rdi
call   1030 <semaphore_enter@plt>
jmp    1178 <semaphore_enter_ordered+0x68>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    116a <semaphore_enter_ordered+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <semaphore_enter@plt>
mov    -0x8(%rbp),%rdi
call   1030 <semaphore_enter@plt>
jmp    1173 <semaphore_enter_ordered+0x63>
mov    -0x8(%rbp),%rdi
call   1030 <semaphore_enter@plt>
jmp    1178 <semaphore_enter_ordered+0x68>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semaphore_enter_ordered>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmp    %rsi,%rdi
jae    112c <semaphore_enter_ordered+0x1c>
mov    %rbx,%rdi
call   1030 <semaphore_enter@plt>
mov    %r14,%rdi
jmp    1139 <semaphore_enter_ordered+0x29>
jbe    1136 <semaphore_enter_ordered+0x26>
mov    %r14,%rdi
call   1030 <semaphore_enter@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <semaphore_enter@plt>

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

LLVM IR (-O2):
%struct.semaphore = type { i32 }
define void @semaphore_enter_ordered(%struct.semaphore* %0, %struct.semaphore* %1) {
%3 = icmp ult %struct.semaphore* %0, %1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @semaphore_enter(%struct.semaphore* %0)
%6 = tail call i32 @semaphore_enter(%struct.semaphore* %1)
br label %14
7: ; preds = %2
%8 = icmp ugt %struct.semaphore* %0, %1
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @semaphore_enter(%struct.semaphore* %1)
%11 = tail call i32 @semaphore_enter(%struct.semaphore* %0)
br label %14
12: ; preds = %7
%13 = tail call i32 @semaphore_enter(%struct.semaphore* %0)
br label %14
14: ; preds = %9, %12, %4
ret void
}