#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 /*<<< orphan*/ desRound(unsigned char *, unsigned char *, unsigned char *,
                            unsigned char, unsigned char);
int /*<<< orphan*/ doIp(unsigned char *);
int /*<<< orphan*/ doIp_1(unsigned char *);
int /*<<< orphan*/ leftRotKeys(unsigned char *, unsigned char *);
int /*<<< orphan*/ rightRotKeys(unsigned char *, unsigned char *);
int /*<<< orphan*/ swap(unsigned char *, unsigned char *);
void des(unsigned char key[], unsigned char mode, unsigned char data[]) {
  unsigned char i;
  unsigned char left[8];
  unsigned char right[8];
  unsigned char *p = left;
  short DESShift = (mode & 4) ? 0x8103 : 0xc081;
  for (i = 3; i > 0; i--) {
    *p = (key[i - 1] << 4) | (key[i] >> 4);
    p++;
  }
  left[3] = key[0] >> 4;
  right[0] = key[6];
  right[1] = key[5];
  right[2] = key[4];
  right[3] = key[3] & 0x0f;
  if (mode & 1)
    doIp(data);
  do {
    if (!(mode & 4)) {
      leftRotKeys(left, right);
      if (!(DESShift & 0x8000))
        leftRotKeys(left, right);
    }
    desRound(left, right, data, mode, key[7]);
    if (mode & 4) {
      rightRotKeys(left, right);
      if (!(DESShift & 0x8000))
        rightRotKeys(left, right);
    }
    DESShift <<= 1;
  } while (DESShift);
  swap(data, data + 4);
  if (mode & 2)
    doIp_1(data);
}


x86 assembly (clang, -O0):
<des>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x21(%rbp),%rax
mov    %rax,-0x38(%rbp)
movzbl -0x9(%rbp),%edx
and    $0x4,%edx
mov    $0xc081,%eax
mov    $0x8103,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %ax,-0x3a(%rbp)
movb   $0x3,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jle    11f1 <des+0x91>
mov    -0x8(%rbp),%rax
movzbl -0x19(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movzbl -0x19(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x19(%rbp),%al
add    $0xff,%al
mov    %al,-0x19(%rbp)
jmp    119d <des+0x3d>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sar    $0x4,%eax
mov    %al,-0x1e(%rbp)
mov    -0x8(%rbp),%rax
mov    0x6(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%al
mov    %al,-0x27(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xf,%eax
mov    %al,-0x26(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1243 <des+0xe3>
mov    -0x18(%rbp),%rdi
call   1070 <doIp@plt>
jmp    1248 <des+0xe8>
movzbl -0x9(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    1289 <des+0x129>
lea    -0x21(%rbp),%rdi
lea    -0x29(%rbp),%rsi
call   1050 <leftRotKeys@plt>
movswl -0x3a(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
jne    1284 <des+0x124>
lea    -0x21(%rbp),%rdi
lea    -0x29(%rbp),%rsi
call   1050 <leftRotKeys@plt>
jmp    1289 <des+0x129>
lea    -0x21(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
movzbl %cl,%ecx
movzbl 0x7(%rax),%r8d
call   1030 <desRound@plt>
movzbl -0x9(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     12ea <des+0x18a>
lea    -0x21(%rbp),%rdi
lea    -0x29(%rbp),%rsi
call   1040 <rightRotKeys@plt>
movswl -0x3a(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
jne    12e5 <des+0x185>
lea    -0x21(%rbp),%rdi
lea    -0x29(%rbp),%rsi
call   1040 <rightRotKeys@plt>
jmp    12ea <des+0x18a>
movswl -0x3a(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0x3a(%rbp)
cmpw   $0x0,-0x3a(%rbp)
jne    1248 <des+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
call   1080 <swap@plt>
movzbl -0x9(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     132a <des+0x1ca>
mov    -0x18(%rbp),%rdi
call   1060 <doIp_1@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<des>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    0x2(%rdi),%bl
mov    0x3(%rdi),%al
mov    %eax,%edx
shr    $0x4,%dl
mov    %ebx,%ecx
shl    $0x4,%cl
or     %dl,%cl
mov    %cl,0x8(%rsp)
mov    0x1(%rdi),%cl
shr    $0x4,%bl
mov    %ecx,%edx
shl    $0x4,%dl
or     %bl,%dl
mov    %dl,0x9(%rsp)
mov    (%rdi),%bl
shr    $0x4,%cl
mov    %ebx,%edx
shl    $0x4,%dl
or     %cl,%dl
test   $0x4,%sil
mov    $0xc081,%ecx
mov    $0x8103,%r14d
cmove  %ecx,%r14d
mov    %dl,0xa(%rsp)
shr    $0x4,%bl
mov    %bl,0xb(%rsp)
mov    0x6(%rdi),%cl
mov    %cl,(%rsp)
mov    0x5(%rdi),%cl
mov    %cl,0x1(%rsp)
mov    %rdi,0x10(%rsp)
mov    0x4(%rdi),%cl
mov    %cl,0x2(%rsp)
and    $0xf,%al
mov    %al,0x3(%rsp)
mov    %esi,%r12d
test   $0x1,%sil
je     11f2 <des+0x92>
mov    %r15,%rdi
call   1070 <doIp@plt>
lea    0x8(%rsp),%rbp
mov    %rsp,%rbx
movzbl %r12b,%r13d
jmp    1224 <des+0xc4>
mov    0x10(%rsp),%rax
movzbl 0x7(%rax),%r8d
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1030 <desRound@plt>
add    %r14d,%r14d
test   %r14w,%r14w
je     1289 <des+0x129>
test   $0x4,%r12b
jne    1250 <des+0xf0>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <leftRotKeys@plt>
test   %r14w,%r14w
js     1200 <des+0xa0>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <leftRotKeys@plt>
jmp    1200 <des+0xa0>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
movzbl 0x7(%rax),%r8d
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1030 <desRound@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <rightRotKeys@plt>
test   %r14w,%r14w
js     121b <des+0xbb>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <rightRotKeys@plt>
jmp    121b <des+0xbb>
lea    0x4(%r15),%rsi
mov    %r15,%rdi
call   1080 <swap@plt>
test   $0x2,%r12b
je     12a3 <des+0x143>
mov    %r15,%rdi
call   1060 <doIp_1@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @des(i8* %0, i8 zeroext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
%8 = alloca [8 x i8]
%9 = alloca [8 x i8]
%10 = alloca i8*
%11 = alloca i16
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
store i8* %12, i8** %10
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = and i32 %14, 4
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 33027, i32 49281
%19 = trunc i32 %18 to i16
store i16 %19, i16* %11
store i8 3, i8* %7
br label %20
20: ; preds = %46, %3
%21 = load i8, i8* %7
%22 = zext i8 %21 to i32
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8, i8* %7
%27 = zext i8 %26 to i32
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 4
%34 = load i8*, i8** %4
%35 = load i8, i8* %7
%36 = zext i8 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = ashr i32 %39, 4
%41 = or i32 %33, %40
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %10
store i8 %42, i8* %43
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %10
br label %46
46: ; preds = %24
%47 = load i8, i8* %7
%48 = add i8 %47, -1
store i8 %48, i8* %7
br label %20
49: ; preds = %20
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = ashr i32 %53, 4
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 3
store i8 %55, i8* %56
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 6
%59 = load i8, i8* %58
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
store i8 %59, i8* %60
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 5
%63 = load i8, i8* %62
%64 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 1
store i8 %63, i8* %64
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i64 4
%67 = load i8, i8* %66
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 2
store i8 %67, i8* %68
%69 = load i8*, i8** %4
%70 = getelementptr inbounds i8, i8* %69, i64 3
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = and i32 %72, 15
%74 = trunc i32 %73 to i8
%75 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 3
store i8 %74, i8* %75
%76 = load i8, i8* %5
%77 = zext i8 %76 to i32
%78 = and i32 %77, 1
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %49
%81 = load i8*, i8** %6
%82 = call i32 @doIp(i8* %81)
br label %83
83: ; preds = %80, %49
br label %84
84: ; preds = %133, %83
%85 = load i8, i8* %5
%86 = zext i8 %85 to i32
%87 = and i32 %86, 4
%88 = icmp ne i32 %87, 0
br i1 %88, label %102, label %89
89: ; preds = %84
%90 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%91 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%92 = call i32 @leftRotKeys(i8* %90, i8* %91)
%93 = load i16, i16* %11
%94 = sext i16 %93 to i32
%95 = and i32 %94, 32768
%96 = icmp ne i32 %95, 0
br i1 %96, label %101, label %97
97: ; preds = %89
%98 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%99 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%100 = call i32 @leftRotKeys(i8* %98, i8* %99)
br label %101
101: ; preds = %97, %89
br label %102
102: ; preds = %101, %84
%103 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%104 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%105 = load i8*, i8** %6
%106 = load i8, i8* %5
%107 = load i8*, i8** %4
%108 = getelementptr inbounds i8, i8* %107, i64 7
%109 = load i8, i8* %108
%110 = call i32 @desRound(i8* %103, i8* %104, i8* %105, i8 zeroext %106, i8 zeroext %109)
%111 = load i8, i8* %5
%112 = zext i8 %111 to i32
%113 = and i32 %112, 4
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %128
115: ; preds = %102
%116 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%117 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%118 = call i32 @rightRotKeys(i8* %116, i8* %117)
%119 = load i16, i16* %11
%120 = sext i16 %119 to i32
%121 = and i32 %120, 32768
%122 = icmp ne i32 %121, 0
br i1 %122, label %127, label %123
123: ; preds = %115
%124 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%125 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%126 = call i32 @rightRotKeys(i8* %124, i8* %125)
br label %127
127: ; preds = %123, %115
br label %128
128: ; preds = %127, %102
%129 = load i16, i16* %11
%130 = sext i16 %129 to i32
%131 = shl i32 %130, 1
%132 = trunc i32 %131 to i16
store i16 %132, i16* %11
br label %133
133: ; preds = %128
%134 = load i16, i16* %11
%135 = icmp ne i16 %134, 0
br i1 %135, label %84, label %136
136: ; preds = %133
%137 = load i8*, i8** %6
%138 = load i8*, i8** %6
%139 = getelementptr inbounds i8, i8* %138, i64 4
%140 = call i32 @swap(i8* %137, i8* %139)
%141 = load i8, i8* %5
%142 = zext i8 %141 to i32
%143 = and i32 %142, 2
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %148
145: ; preds = %136
%146 = load i8*, i8** %6
%147 = call i32 @doIp_1(i8* %146)
br label %148
148: ; preds = %145, %136
ret void
}

LLVM IR (-O2):
define void @des(i8* nocapture %0, i8 zeroext %1, i8* %2) {
%4 = alloca [8 x i8]
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = zext i8 %1 to i32
%9 = and i32 %8, 4
%10 = icmp eq i32 %9, 0
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
%15 = tail call i8 @llvm.fshl.i8(i8 %12, i8 %14, i8 4)
store i8 %15, i8* %6
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
%17 = getelementptr inbounds i8, i8* %0, i64 1
%18 = load i8, i8* %17
%19 = tail call i8 @llvm.fshl.i8(i8 %18, i8 %12, i8 4)
store i8 %19, i8* %16
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 2
%21 = load i8, i8* %0
%22 = tail call i8 @llvm.fshl.i8(i8 %21, i8 %18, i8 4)
store i8 %22, i8* %20
%23 = select i1 %10, i16 -16255, i16 -32509
%24 = lshr i8 %21, 4
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 3
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %0, i64 6
%27 = load i8, i8* %26
store i8 %27, i8* %7
%28 = getelementptr inbounds i8, i8* %0, i64 5
%29 = load i8, i8* %28
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
store i8 %29, i8* %30
%31 = getelementptr inbounds i8, i8* %0, i64 4
%32 = load i8, i8* %31
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 2
store i8 %32, i8* %33
%34 = and i8 %14, 15
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 3
store i8 %34, i8* %35
%36 = and i32 %8, 1
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %3
%39 = tail call i32 @doIp(i8* %2)
br label %40
40: ; preds = %38, %3
%41 = getelementptr inbounds i8, i8* %0, i64 7
br label %42
42: ; preds = %59, %40
%43 = phi i16 [ %23, %40 ], [ %60, %59 ]
br i1 %10, label %44, label %52
44: ; preds = %42
%45 = call i32 @leftRotKeys(i8* %6, i8* %7)
%46 = icmp sgt i16 %43, -1
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @leftRotKeys(i8* %6, i8* %7)
br label %49
49: ; preds = %44, %47
%50 = load i8, i8* %41
%51 = call i32 @desRound(i8* %6, i8* %7, i8* %2, i8 zeroext %1, i8 zeroext %50)
br label %59
52: ; preds = %42
%53 = load i8, i8* %41
%54 = call i32 @desRound(i8* %6, i8* %7, i8* %2, i8 zeroext %1, i8 zeroext %53)
%55 = call i32 @rightRotKeys(i8* %6, i8* %7)
%56 = icmp sgt i16 %43, -1
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @rightRotKeys(i8* %6, i8* %7)
br label %59
59: ; preds = %49, %52, %57
%60 = shl i16 %43, 1
%61 = icmp eq i16 %60, 0
br i1 %61, label %62, label %42
62: ; preds = %59
%63 = getelementptr inbounds i8, i8* %2, i64 4
%64 = call i32 @swap(i8* %2, i8* %63)
%65 = and i32 %8, 2
%66 = icmp eq i32 %65, 0
br i1 %66, label %69, label %67
67: ; preds = %62
%68 = call i32 @doIp_1(i8* %2)
br label %69
69: ; preds = %67, %62
ret void
}