#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 timeval {
  int tv_sec;
  int tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int do_encode(unsigned char *, unsigned char *, size_t, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
unsigned char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read_data(int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  FILE *in, *out;
  int i;
  size_t size;
  int outsize, time;
  unsigned char *inbuf, *outbuf, *temp;
  struct timeval pre, post;
  inbuf = malloc(1000000);
  outbuf = malloc(1000000 * 2);
  if (argc > 1) {
    if ((in = fopen(argv[1], "r")) == NULL) {
      perror(argv[1]);
      exit(1);
    }
    argc--;
  } else {
    in = stdin;
    out = stdout;
  }
  if (argc != 1) {
    printf("Usage: uuencode [infile]\n");
    exit(2);
  }
  size = read_data(in, inbuf);
  gettimeofday(&pre, 0);
  for (i = 0; i < 1000; i++) {
    char *infilename = "uuencode.c";
    outsize = do_encode(inbuf, outbuf, size, infilename);
  }
  gettimeofday(&post, 0);
  time = ((post.tv_sec * 1000000 + post.tv_usec) -
          (pre.tv_sec * 1000000 + pre.tv_usec));
  printf("%d\n", outsize);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xf4240,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1e8480,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1203 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    121f <main+0x9f>
mov    0x2dde(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1241 <main+0xc1>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <read_data@plt>
mov    %rax,-0x30(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    12a2 <main+0x122>
lea    0xda4(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x68(%rbp),%rcx
call   1090 <do_encode@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1264 <main+0xe4>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x60(%rbp),%eax
add    -0x5c(%rbp),%eax
imul   $0xf4240,-0x58(%rbp),%ecx
add    -0x54(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%esi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0xf4240,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x1e8480,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%ebp
jl     11ee <main+0x5e>
mov    0x8(%r15),%rdi
lea    0xe33(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    126b <main+0xdb>
mov    0x8(%r15),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
cmp    $0x1,%ebp
jne    1273 <main+0xe3>
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <read_data@plt>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    $0x3e8,%ebp
lea    0xddf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
call   10a0 <do_encode@plt>
add    $0xffffffff,%ebp
jne    1230 <main+0xa0>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0xdb2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
je     11fd <main+0x6d>
lea    0xd97(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.1 = [26 x i8] c"Usage: uuencode [infile]\0A\00"
@.str.2 = [11 x i8] c"uuencode.c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca %struct.timeval
%16 = alloca %struct.timeval
%17 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = call i8* @malloc(i32 1000000)
store i8* %18, i8** %12
%19 = call i8* @malloc(i32 2000000)
store i8* %19, i8** %13
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %37
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @perror(i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %22
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
br label %40
37: ; preds = %2
%38 = load i32*, i32** @stdin
store i32* %38, i32** %6
%39 = load i32*, i32** @stdout
store i32* %39, i32** %7
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%45 = call i32 @exit(i32 2)
unreachable
46: ; preds = %40
%47 = load i32*, i32** %6
%48 = load i8*, i8** %12
%49 = call i64 @read_data(i32* %47, i8* %48)
store i64 %49, i64* %9
%50 = call i32 @gettimeofday(%struct.timeval* %15, i32 0)
store i32 0, i32* %8
br label %51
51: ; preds = %60, %46
%52 = load i32, i32* %8
%53 = icmp slt i32 %52, 1000
br i1 %53, label %54, label %63
54: ; preds = %51
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %17
%55 = load i8*, i8** %12
%56 = load i8*, i8** %13
%57 = load i64, i64* %9
%58 = load i8*, i8** %17
%59 = call i32 @do_encode(i8* %55, i8* %56, i64 %57, i8* %58)
store i32 %59, i32* %10
br label %60
60: ; preds = %54
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %51
63: ; preds = %51
%64 = call i32 @gettimeofday(%struct.timeval* %16, i32 0)
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%66 = load i32, i32* %65
%67 = mul nsw i32 %66, 1000000
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%69 = load i32, i32* %68
%70 = add nsw i32 %67, %69
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%72 = load i32, i32* %71
%73 = mul nsw i32 %72, 1000000
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%75 = load i32, i32* %74
%76 = add nsw i32 %73, %75
%77 = sub nsw i32 %70, %76
store i32 %77, i32* %11
%78 = load i32, i32* %10
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %78)
%80 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.2 = [11 x i8] c"uuencode.c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [25 x i8] c"Usage: uuencode [infile]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = tail call dereferenceable_or_null(1000000) i8* @malloc(i32 1000000)
%8 = tail call dereferenceable_or_null(2000000) i8* @malloc(i32 2000000)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = add nsw i32 %0, -1
br label %23
21: ; preds = %2
%22 = load i32*, i32** @stdin
br label %23
23: ; preds = %21, %19
%24 = phi i32* [ %13, %19 ], [ %22, %21 ]
%25 = phi i32 [ %20, %19 ], [ %0, %21 ]
%26 = icmp eq i32 %25, 1
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 2)
unreachable
30: ; preds = %23
%31 = tail call i64 @read_data(i32* %24, i8* %7)
%32 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
br label %33
33: ; preds = %30, %33
%34 = phi i32 [ 0, %30 ], [ %36, %33 ]
%35 = call i32 @do_encode(i8* %7, i8* %8, i64 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%36 = add nuw nsw i32 %34, 1
%37 = icmp eq i32 %36, 1000
br i1 %37, label %38, label %33
38: ; preds = %33
%39 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%41 = call i32 @exit(i32 0)
unreachable
}