#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int readbyte(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ writebyte(int /*<<< orphan*/ *, char);
int crypt01(FILE *ifile, FILE *ofile, char *key, int v) {
  char b1, b2;
  int n1 = 1, n2 = 1;
  int count = 0;
  if (v)
    printf("Swap byte method :");
  while (n1 && n2) {
    n1 = readbyte(ifile, &b1);
    n2 = readbyte(ifile, &b2);
    if (n2) {
      count++;
      writebyte(ofile, b2);
    }
    if (n1) {
      count++;
      writebyte(ofile, b1);
    }
  }
  if (v)
    printf(" %d bytes swapped!\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<crypt01>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1174 <crypt01+0x44>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1179 <crypt01+0x49>
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x2d(%rbp)
je     1192 <crypt01+0x62>
cmpl   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11a2 <crypt01+0x72>
jmp    1207 <crypt01+0xd7>
mov    -0x8(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1040 <readbyte@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1040 <readbyte@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11e2 <crypt01+0xb2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x1e(%rbp),%esi
call   1050 <writebyte@plt>
cmpl   $0x0,-0x24(%rbp)
je     1202 <crypt01+0xd2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x1d(%rbp),%esi
call   1050 <writebyte@plt>
jmp    1179 <crypt01+0x49>
cmpl   $0x0,-0x1c(%rbp)
je     1222 <crypt01+0xf2>
mov    -0x2c(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt01>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,0x4(%rsp)
test   %ecx,%ecx
je     1157 <crypt01+0x27>
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebp,%ebp
lea    0x2(%rsp),%r13
xchg   %ax,%ax
mov    %rbx,%rdi
lea    0x3(%rsp),%rsi
call   1040 <readbyte@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <readbyte@plt>
mov    %eax,%r14d
test   %eax,%eax
je     1192 <crypt01+0x62>
add    $0x1,%ebp
movsbl 0x2(%rsp),%esi
mov    %r15,%rdi
call   1050 <writebyte@plt>
test   %r12d,%r12d
je     11ac <crypt01+0x7c>
add    $0x1,%ebp
movsbl 0x3(%rsp),%esi
mov    %r15,%rdi
call   1050 <writebyte@plt>
test   %r14d,%r14d
jne    1160 <crypt01+0x30>
cmpl   $0x0,0x4(%rsp)
je     11c3 <crypt01+0x93>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Swap byte method :\00"
@.str.1 = [20 x i8] c" %d bytes swapped!\0A\00"
define i32 @crypt01(i32* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 1, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %4
br label %19
19: ; preds = %49, %18
%20 = load i32, i32* %11
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %12
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %22, %19
%26 = phi i1 [ false, %19 ], [ %24, %22 ]
br i1 %26, label %27, label %50
27: ; preds = %25
%28 = load i32*, i32** %5
%29 = call i32 @readbyte(i32* %28, i8* %9)
store i32 %29, i32* %11
%30 = load i32*, i32** %5
%31 = call i32 @readbyte(i32* %30, i8* %10)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %13
%36 = add nsw i32 %35, 1
store i32 %36, i32* %13
%37 = load i32*, i32** %6
%38 = load i8, i8* %10
%39 = call i32 @writebyte(i32* %37, i8 signext %38)
br label %40
40: ; preds = %34, %27
%41 = load i32, i32* %11
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 1
store i32 %45, i32* %13
%46 = load i32*, i32** %6
%47 = load i8, i8* %9
%48 = call i32 @writebyte(i32* %46, i8 signext %47)
br label %49
49: ; preds = %43, %40
br label %19
50: ; preds = %25
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %13
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Swap byte method :\00"
@.str.1 = [20 x i8] c" %d bytes swapped!\0A\00"
define i32 @crypt01(i32* %0, i32* %1, i8* nocapture readnone %2, i32 %3) {
%5 = alloca i8
%6 = alloca i8
%7 = icmp eq i32 %3, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
br label %11
11: ; preds = %10, %23
%12 = phi i32 [ %24, %23 ], [ 0, %10 ]
%13 = call i32 @readbyte(i32* %0, i8* %5)
%14 = call i32 @readbyte(i32* %0, i8* %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = add nsw i32 %12, 1
%18 = load i8, i8* %6
%19 = call i32 @writebyte(i32* %1, i8 signext %18)
br label %20
20: ; preds = %16, %11
%21 = phi i32 [ %17, %16 ], [ %12, %11 ]
%22 = icmp eq i32 %13, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = add nsw i32 %21, 1
%25 = load i8, i8* %5
%26 = call i32 @writebyte(i32* %1, i8 signext %25)
%27 = icmp eq i32 %14, 0
br i1 %27, label %28, label %11
28: ; preds = %20, %23
%29 = phi i32 [ %24, %23 ], [ %21, %20 ]
br i1 %7, label %32, label %30
30: ; preds = %28
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %32
32: ; preds = %30, %28
ret i32 0
}