#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 char uint32_t;
typedef char u_char;
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ R_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ btea(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int getpid();
char htonl(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int open(char *, int, ...);
void *rand();
int read(int, char *, int);
int /*<<< orphan*/ srand(int);
int stat(char *, struct stat *);
scalar_t__ time(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int xxtea_encrypt(char *in_file, char *out_file, char *key) {
  extern int errno;
  int c;
  int i;
  int j;
  int sl;
  int first_block = 1;
  int fd_in;
  int fd_out;
  int bl = 0;
  int bytes_read;
  int pad = 0;
  int trnd = 0;
  int uid;
  int use_file = 0;
  uint32_t randpad[16];
  off_t filesize = 0;
  uint32_t filesize_msb = 0;
  uint32_t read_filesize_msb = 0;
  uint32_t read_filesize = 0;
  uint32_t bsf = 0;
  char fb_buffer[64];
  u_char plaintext[64];
  struct stat statbuf;
  if (in_file != NULL) {
    if (-1 == (stat(in_file, &statbuf))) {
      return 1;
    } else {
      filesize = statbuf.st_size;
      filesize_msb = htonl(filesize);
    }
    if (-1 == access(in_file, R_OK)) {
      return 2;
    }
    if (-1 == (fd_in = open(in_file, O_RDONLY))) {
      return 1;
    }
  } else {
    return 1;
  }
  if (-1 == (fd_out = open(out_file, O_WRONLY | O_CREAT | O_EXCL, 00600))) {
    return 4;
  }
  for (i = 0; i < 16; i++) {
    srand(i);
    trnd = rand();
    srand((int)time(0) + getpid() + i + trnd);
    randpad[i] = rand();
  }
  while (first_block) {
    bytes_read = read(fd_in, plaintext, 60);
    if (bytes_read == -1) {
      return 5;
    }
    if (bytes_read != 60) {
      pad = 60 - bytes_read;
      memcpy(plaintext + bytes_read, randpad, pad);
    }
    memcpy(fb_buffer, &filesize_msb, 4);
    memcpy(fb_buffer + 4, plaintext, 60);
    btea((int32_t *)fb_buffer, 16, (int32_t *)key);
    write(fd_out, (char *)fb_buffer, 64);
    first_block = 0;
  }
  while ((bytes_read = read(fd_in, plaintext, 64))) {
    if (bytes_read == 64) {
      btea((int32_t *)plaintext, 16, (int32_t *)key);
      write(fd_out, (char *)plaintext, 64);
    } else {
      pad = 64 - bytes_read;
      memcpy(plaintext + bytes_read, randpad, pad);
      btea((int32_t *)plaintext, 16, (int32_t *)key);
      write(fd_out, (char *)plaintext, 64);
    }
  }
  close(fd_out);
  close(fd_in);
  return (0);
}


x86 assembly (clang, -O0):
<xxtea_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x74(%rbp)
movb   $0x0,-0x75(%rbp)
movb   $0x0,-0x76(%rbp)
movb   $0x0,-0x77(%rbp)
movb   $0x0,-0x78(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12cf <xxtea_encrypt+0xff>
mov    -0x10(%rbp),%rdi
lea    -0x108(%rbp),%rsi
call   10a0 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1257 <xxtea_encrypt+0x87>
movl   $0x1,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
mov    -0x108(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edi
call   1060 <htonl@plt>
mov    %al,-0x75(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1298 <xxtea_encrypt+0xc8>
movl   $0x2,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
mov    -0x10(%rbp),%rdi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x38(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12ca <xxtea_encrypt+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
jmp    12db <xxtea_encrypt+0x10b>
movl   $0x1,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
mov    -0x18(%rbp),%rdi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
mov    0x2d09(%rip),%rax
or     (%rax),%esi
mov    0x2cd8(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1324 <xxtea_encrypt+0x154>
movl   $0x4,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    138d <xxtea_encrypt+0x1bd>
mov    -0x28(%rbp),%edi
call   1090 <srand@plt>
mov    $0x0,%al
call   10f0 <rand@plt>
mov    %eax,-0x4c(%rbp)
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,-0x10c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x10c(%rbp),%edi
add    %eax,%edi
add    -0x28(%rbp),%edi
add    -0x4c(%rbp),%edi
call   1090 <srand@plt>
mov    $0x0,%al
call   10f0 <rand@plt>
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    132b <xxtea_encrypt+0x15b>
jmp    1392 <xxtea_encrypt+0x1c2>
cmpl   $0x0,-0x34(%rbp)
je     145e <xxtea_encrypt+0x28e>
mov    -0x38(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x3c,%edx
call   1080 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    13c9 <xxtea_encrypt+0x1f9>
movl   $0x5,-0x4(%rbp)
jmp    1525 <xxtea_encrypt+0x355>
cmpl   $0x3c,-0x44(%rbp)
je     13f8 <xxtea_encrypt+0x228>
mov    $0x3c,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
lea    -0x100(%rbp),%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
lea    -0x70(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   10b0 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    -0x75(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
add    $0x4,%rdi
lea    -0x100(%rbp),%rsi
mov    $0x3c,%edx
call   10b0 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x10,%esi
call   1050 <btea@plt>
mov    -0x3c(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x40,%edx
call   1030 <write@plt>
movl   $0x0,-0x34(%rbp)
jmp    1392 <xxtea_encrypt+0x1c2>
jmp    1463 <xxtea_encrypt+0x293>
mov    -0x38(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x40,%edx
call   1080 <read@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     150e <xxtea_encrypt+0x33e>
cmpl   $0x40,-0x44(%rbp)
jne    14bb <xxtea_encrypt+0x2eb>
lea    -0x100(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x10,%esi
call   1050 <btea@plt>
mov    -0x3c(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x40,%edx
call   1030 <write@plt>
jmp    1509 <xxtea_encrypt+0x339>
mov    $0x40,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
lea    -0x100(%rbp),%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
lea    -0x70(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   10b0 <memcpy@plt>
lea    -0x100(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x10,%esi
call   1050 <btea@plt>
mov    -0x3c(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x40,%edx
call   1030 <write@plt>
jmp    1463 <xxtea_encrypt+0x293>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxtea_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    $0x1,%ebx
test   %rdi,%rdi
je     13eb <xxtea_encrypt+0x21b>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x8(%rsp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     13eb <xxtea_encrypt+0x21b>
mov    0x8(%rsp),%edi
call   1060 <htonl@plt>
mov    %al,0x7(%rsp)
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10e0 <access@plt>
cmp    $0xffffffff,%eax
je     13c4 <xxtea_encrypt+0x1f4>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13eb <xxtea_encrypt+0x21b>
mov    %eax,%r12d
mov    0x2d60(%rip),%rax
mov    0x2d99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d66(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13df <xxtea_encrypt+0x20f>
mov    %eax,%r13d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
call   1090 <srand@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
mov    %rax,%r15
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
add    %eax,%ebx
add    %r15d,%ebx
add    %ebp,%ebx
mov    %ebx,%edi
call   1090 <srand@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
mov    %al,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0x10,%rbp
jne    1290 <xxtea_encrypt+0xc0>
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
mov    $0x3c,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     13e6 <xxtea_encrypt+0x216>
cmp    $0x3c,%eax
je     1310 <xxtea_encrypt+0x140>
mov    $0x3c,%edx
sub    %eax,%edx
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
lea    0x10(%rsp),%rsi
call   10b0 <memcpy@plt>
lea    0x60(%rsp),%rbx
lea    0x7(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    0x64(%rsp),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x3c,%edx
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   1050 <btea@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%r15
jmp    1390 <xxtea_encrypt+0x1c0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   1050 <btea@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
call   1080 <read@plt>
cmp    $0x40,%eax
je     1370 <xxtea_encrypt+0x1a0>
test   %eax,%eax
je     13cb <xxtea_encrypt+0x1fb>
mov    $0x40,%edx
sub    %eax,%edx
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
mov    %r15,%rsi
call   10b0 <memcpy@plt>
jmp    1370 <xxtea_encrypt+0x1a0>
mov    $0x2,%ebx
jmp    13eb <xxtea_encrypt+0x21b>
mov    %r13d,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %ebx,%ebx
jmp    13eb <xxtea_encrypt+0x21b>
mov    $0x4,%ebx
jmp    13eb <xxtea_encrypt+0x21b>
mov    $0x5,%ebx
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@R_OK = global i32 0
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define i32 @xxtea_encrypt(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca [16 x i8]
%22 = alloca i32
%23 = alloca i8
%24 = alloca i8
%25 = alloca i8
%26 = alloca i8
%27 = alloca [64 x i8]
%28 = alloca [64 x i8]
%29 = alloca %struct.stat
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 1, i32* %12
store i32 0, i32* %15
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %20
store i32 0, i32* %22
store i8 0, i8* %23
store i8 0, i8* %24
store i8 0, i8* %25
store i8 0, i8* %26
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %55
32: ; preds = %3
%33 = load i8*, i8** %5
%34 = call i32 @stat(i8* %33, %struct.stat* %29)
%35 = icmp eq i32 -1, %34
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 1, i32* %4
br label %173
37: ; preds = %32
%38 = getelementptr inbounds %struct.stat, %struct.stat* %29, i32 0, i32 0
%39 = load i32, i32* %38
store i32 %39, i32* %22
%40 = load i32, i32* %22
%41 = call signext i8 @htonl(i32 %40)
store i8 %41, i8* %23
br label %42
42: ; preds = %37
%43 = load i8*, i8** %5
%44 = load i32, i32* @R_OK
%45 = call i32 @access(i8* %43, i32 %44)
%46 = icmp eq i32 -1, %45
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 2, i32* %4
br label %173
48: ; preds = %42
%49 = load i8*, i8** %5
%50 = load i32, i32* @O_RDONLY
%51 = call i32 (i8*, i32, ...) @open(i8* %49, i32 %50)
store i32 %51, i32* %13
%52 = icmp eq i32 -1, %51
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 1, i32* %4
br label %173
54: ; preds = %48
br label %56
55: ; preds = %3
store i32 1, i32* %4
br label %173
56: ; preds = %54
%57 = load i8*, i8** %6
%58 = load i32, i32* @O_WRONLY
%59 = load i32, i32* @O_CREAT
%60 = or i32 %58, %59
%61 = load i32, i32* @O_EXCL
%62 = or i32 %60, %61
%63 = call i32 (i8*, i32, ...) @open(i8* %57, i32 %62, i32 384)
store i32 %63, i32* %14
%64 = icmp eq i32 -1, %63
br i1 %64, label %65, label %66
65: ; preds = %56
store i32 4, i32* %4
br label %173
66: ; preds = %56
store i32 0, i32* %9
br label %67
67: ; preds = %89, %66
%68 = load i32, i32* %9
%69 = icmp slt i32 %68, 16
br i1 %69, label %70, label %92
70: ; preds = %67
%71 = load i32, i32* %9
%72 = call i32 @srand(i32 %71)
%73 = call i8* (...) @rand()
%74 = ptrtoint i8* %73 to i32
store i32 %74, i32* %18
%75 = call i64 @time(i32 0)
%76 = trunc i64 %75 to i32
%77 = call i32 (...) @getpid()
%78 = add nsw i32 %76, %77
%79 = load i32, i32* %9
%80 = add nsw i32 %78, %79
%81 = load i32, i32* %18
%82 = add nsw i32 %80, %81
%83 = call i32 @srand(i32 %82)
%84 = call i8* (...) @rand()
%85 = ptrtoint i8* %84 to i8
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 %87
store i8 %85, i8* %88
br label %89
89: ; preds = %70
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %67
92: ; preds = %67
br label %93
93: ; preds = %116, %92
%94 = load i32, i32* %12
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %131
96: ; preds = %93
%97 = load i32, i32* %13
%98 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%99 = call i32 @read(i32 %97, i8* %98, i32 60)
store i32 %99, i32* %16
%100 = load i32, i32* %16
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %103
102: ; preds = %96
store i32 5, i32* %4
br label %173
103: ; preds = %96
%104 = load i32, i32* %16
%105 = icmp ne i32 %104, 60
br i1 %105, label %106, label %116
106: ; preds = %103
%107 = load i32, i32* %16
%108 = sub nsw i32 60, %107
store i32 %108, i32* %17
%109 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%110 = load i32, i32* %16
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
%113 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%114 = load i32, i32* %17
%115 = call i32 @memcpy(i8* %112, i8* %113, i32 %114)
br label %116
116: ; preds = %106, %103
%117 = getelementptr inbounds [64 x i8], [64 x i8]* %27, i64 0, i64 0
%118 = call i32 @memcpy(i8* %117, i8* %23, i32 4)
%119 = getelementptr inbounds [64 x i8], [64 x i8]* %27, i64 0, i64 0
%120 = getelementptr inbounds i8, i8* %119, i64 4
%121 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%122 = call i32 @memcpy(i8* %120, i8* %121, i32 60)
%123 = getelementptr inbounds [64 x i8], [64 x i8]* %27, i64 0, i64 0
%124 = bitcast i8* %123 to i32*
%125 = load i8*, i8** %7
%126 = bitcast i8* %125 to i32*
%127 = call i32 @btea(i32* %124, i32 16, i32* %126)
%128 = load i32, i32* %14
%129 = getelementptr inbounds [64 x i8], [64 x i8]* %27, i64 0, i64 0
%130 = call i32 @write(i32 %128, i8* %129, i32 64)
store i32 0, i32* %12
br label %93
131: ; preds = %93
br label %132
132: ; preds = %167, %131
%133 = load i32, i32* %13
%134 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 64)
store i32 %135, i32* %16
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %168
137: ; preds = %132
%138 = load i32, i32* %16
%139 = icmp eq i32 %138, 64
br i1 %139, label %140, label %149
140: ; preds = %137
%141 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%142 = bitcast i8* %141 to i32*
%143 = load i8*, i8** %7
%144 = bitcast i8* %143 to i32*
%145 = call i32 @btea(i32* %142, i32 16, i32* %144)
%146 = load i32, i32* %14
%147 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%148 = call i32 @write(i32 %146, i8* %147, i32 64)
br label %167
149: ; preds = %137
%150 = load i32, i32* %16
%151 = sub nsw i32 64, %150
store i32 %151, i32* %17
%152 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%153 = load i32, i32* %16
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8, i8* %152, i64 %154
%156 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%157 = load i32, i32* %17
%158 = call i32 @memcpy(i8* %155, i8* %156, i32 %157)
%159 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%160 = bitcast i8* %159 to i32*
%161 = load i8*, i8** %7
%162 = bitcast i8* %161 to i32*
%163 = call i32 @btea(i32* %160, i32 16, i32* %162)
%164 = load i32, i32* %14
%165 = getelementptr inbounds [64 x i8], [64 x i8]* %28, i64 0, i64 0
%166 = call i32 @write(i32 %164, i8* %165, i32 64)
br label %167
167: ; preds = %149, %140
br label %132
168: ; preds = %132
%169 = load i32, i32* %14
%170 = call i32 @close(i32 %169)
%171 = load i32, i32* %13
%172 = call i32 @close(i32 %171)
store i32 0, i32* %4
br label %173
173: ; preds = %168, %102, %65, %55, %53, %47, %36
%174 = load i32, i32* %4
ret i32 %174
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@R_OK = global i32 0
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
define i32 @xxtea_encrypt(i8* %0, i8* nocapture %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca i8
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca %struct.stat
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%12 = bitcast %struct.stat* %8 to i8*
%13 = icmp eq i8* %0, null
br i1 %13, label %85, label %14
14: ; preds = %3
%15 = call i32 @stat(i8* %0, %struct.stat* %8)
%16 = icmp eq i32 %15, -1
br i1 %16, label %85, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call signext i8 @htonl(i32 %19)
store i8 %20, i8* %5
%21 = load i32, i32* @R_OK
%22 = tail call i32 @access(i8* %0, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %85, label %24
24: ; preds = %17
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %85, label %28
28: ; preds = %24
%29 = load i32, i32* @O_WRONLY
%30 = load i32, i32* @O_CREAT
%31 = or i32 %30, %29
%32 = load i32, i32* @O_EXCL
%33 = or i32 %31, %32
%34 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %33, i32 384)
%35 = icmp eq i32 %34, -1
br i1 %35, label %85, label %36
36: ; preds = %28, %36
%37 = phi i64 [ %54, %36 ], [ 0, %28 ]
%38 = trunc i64 %37 to i32
%39 = tail call i32 @srand(i32 %38)
%40 = tail call i8* (...) @rand()
%41 = ptrtoint i8* %40 to i64
%42 = trunc i64 %41 to i32
%43 = tail call i64 @time(i32 0)
%44 = trunc i64 %43 to i32
%45 = tail call i32 (...) @getpid()
%46 = add i32 %38, %44
%47 = add i32 %46, %45
%48 = add i32 %47, %42
%49 = tail call i32 @srand(i32 %48)
%50 = tail call i8* (...) @rand()
%51 = ptrtoint i8* %50 to i64
%52 = trunc i64 %51 to i8
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %37
store i8 %52, i8* %53
%54 = add nuw nsw i64 %37, 1
%55 = icmp eq i64 %54, 16
br i1 %55, label %56, label %36
56: ; preds = %36
%57 = call i32 @read(i32 %26, i8* %11, i32 60)
switch i32 %57, label %58 [
i32 -1, label %85
i32 60, label %63
]
58: ; preds = %56
%59 = sub nsw i32 60, %57
%60 = sext i32 %57 to i64
%61 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %60
%62 = call i32 @memcpy(i8* %61, i8* %9, i32 %59)
br label %63
63: ; preds = %56, %58
%64 = call i32 @memcpy(i8* %10, i8* %5, i32 4)
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 4
%66 = call i32 @memcpy(i8* %65, i8* %11, i32 60)
%67 = bitcast [64 x i8]* %6 to i32*
%68 = bitcast i8* %2 to i32*
%69 = call i32 @btea(i32* %67, i32 16, i32* %68)
%70 = call i32 @write(i32 %34, i8* %10, i32 64)
%71 = bitcast [64 x i8]* %7 to i32*
br label %72
72: ; preds = %63, %79
%73 = call i32 @read(i32 %26, i8* %11, i32 64)
switch i32 %73, label %74 [
i32 0, label %82
i32 64, label %79
]
74: ; preds = %72
%75 = sub nsw i32 64, %73
%76 = sext i32 %73 to i64
%77 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %76
%78 = call i32 @memcpy(i8* %77, i8* %9, i32 %75)
br label %79
79: ; preds = %72, %74
%80 = call i32 @btea(i32* %71, i32 16, i32* %68)
%81 = call i32 @write(i32 %34, i8* %11, i32 64)
br label %72
82: ; preds = %72
%83 = call i32 @close(i32 %34)
%84 = call i32 @close(i32 %26)
br label %85
85: ; preds = %56, %28, %3, %24, %17, %14, %82
%86 = phi i32 [ 0, %82 ], [ 1, %14 ], [ 2, %17 ], [ 1, %24 ], [ 1, %3 ], [ 4, %28 ], [ 5, %56 ]
ret i32 %86
}