#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*/ passwd(char *);
int /*<<< orphan*/ printf(char *, ...);
int readbyte(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ writebyte(int /*<<< orphan*/ *, char);
int crypt02(FILE *ifile, FILE *ofile, char *key, int v) {
  char b1;
  int n1 = 1;
  int idx = 0;
  int count = 0;
  if (key[0] == '\0')
    passwd(key);
  if (v)
    printf("Xor method :");
  while (n1) {
    if (key[idx] == '\0')
      idx = 0;
    n1 = readbyte(ifile, &b1);
    if (n1) {
      count++;
      writebyte(ofile, b1 ^ (key[idx]));
    }
    idx++;
  }
  if (v)
    printf(" %d bytes xor'ed!\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<crypt02>:
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   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1185 <crypt02+0x45>
mov    -0x18(%rbp),%rdi
call   1030 <passwd@plt>
cmpl   $0x0,-0x1c(%rbp)
je     119d <crypt02+0x5d>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a2 <crypt02+0x62>
cmpl   $0x0,-0x24(%rbp)
je     1217 <crypt02+0xd7>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11c8 <crypt02+0x88>
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1050 <readbyte@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1209 <crypt02+0xc9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x1d(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
movsbl %al,%esi
call   1060 <writebyte@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a2 <crypt02+0x62>
cmpl   $0x0,-0x1c(%rbp)
je     1232 <crypt02+0xf2>
mov    -0x2c(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt02>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
cmpb   $0x0,(%rdx)
je     11d2 <crypt02+0x92>
test   %ebp,%ebp
je     116d <crypt02+0x2d>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,0x4(%rsp)
lea    0x3(%rsp),%rsi
mov    %r12,%rdi
call   1050 <readbyte@plt>
test   %eax,%eax
je     11e0 <crypt02+0xa0>
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    11a4 <crypt02+0x64>
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %r12,%rdi
lea    0x3(%rsp),%rsi
call   1050 <readbyte@plt>
test   %eax,%eax
je     11e2 <crypt02+0xa2>
movslq %r14d,%r13
movzbl (%rbx,%r13,1),%eax
xor    0x3(%rsp),%al
movsbl %al,%esi
mov    %r15,%rdi
call   1060 <writebyte@plt>
cmpb   $0x0,0x1(%rbx,%r13,1)
mov    $0x0,%r14d
je     1190 <crypt02+0x50>
add    $0x1,%r13
mov    %r13d,%r14d
jmp    1190 <crypt02+0x50>
mov    %rbx,%rdi
call   1030 <passwd@plt>
test   %ebp,%ebp
jne    115f <crypt02+0x1f>
jmp    116d <crypt02+0x2d>
xor    %ebp,%ebp
cmpl   $0x0,0x4(%rsp)
je     11f9 <crypt02+0xb9>
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <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 = [13 x i8] c"Xor method :\00"
@.str.1 = [19 x i8] c" %d bytes xor'ed!\0A\00"
define i32 @crypt02(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 i32
%11 = alloca i32
%12 = 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* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = call i32 @passwd(i8* %19)
br label %21
21: ; preds = %18, %4
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
br label %27
27: ; preds = %59, %26
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %62
30: ; preds = %27
%31 = load i8*, i8** %7
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 0, i32* %11
br label %39
39: ; preds = %38, %30
%40 = load i32*, i32** %5
%41 = call i32 @readbyte(i32* %40, i8* %9)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %59
44: ; preds = %39
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
%47 = load i32*, i32** %6
%48 = load i8, i8* %9
%49 = sext i8 %48 to i32
%50 = load i8*, i8** %7
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = xor i32 %49, %55
%57 = trunc i32 %56 to i8
%58 = call i32 @writebyte(i32* %47, i8 signext %57)
br label %59
59: ; preds = %44, %39
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %27
62: ; preds = %27
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %12
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %62
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Xor method :\00"
@.str.1 = [19 x i8] c" %d bytes xor'ed!\0A\00"
define i32 @crypt02(i32* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i8
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @passwd(i8* %2)
br label %10
10: ; preds = %8, %4
%11 = icmp eq i32 %3, 0
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = call i32 @readbyte(i32* %0, i8* %5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %14, %17
%18 = phi i32 [ %32, %17 ], [ 0, %14 ]
%19 = phi i32 [ %20, %17 ], [ 0, %14 ]
%20 = add nuw nsw i32 %19, 1
%21 = load i8, i8* %5
%22 = sext i32 %18 to i64
%23 = getelementptr inbounds i8, i8* %2, i64 %22
%24 = load i8, i8* %23
%25 = xor i8 %24, %21
%26 = call i32 @writebyte(i32* %1, i8 signext %25)
%27 = add nsw i32 %18, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
%32 = select i1 %31, i32 0, i32 %27
%33 = call i32 @readbyte(i32* %0, i8* %5)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %17
35: ; preds = %17, %14
%36 = phi i32 [ 0, %14 ], [ %20, %17 ]
br i1 %11, label %39, label %37
37: ; preds = %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %39
39: ; preds = %37, %35
ret i32 0
}