#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ krb5_nfold(int, unsigned char *, int, unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int strlen(unsigned char *);
int main(int argc, char *argv[]) {
  int inlen, outlen, i;
  unsigned char *instr, *outstr;
  if (argc != 3) {
    fprintf(stderr, "%s: instr outlen\n", argv[0]);
    exit(1);
  }
  instr = (unsigned char *)argv[1];
  inlen = strlen(instr) * 8;
  outlen = atoi(argv[2]);
  if (outlen % 8) {
    fprintf(stderr, "outlen must be a multiple of 8\n");
    exit(1);
  }
  if ((outstr = (unsigned char *)malloc(outlen / 8)) == NULL) {
    fprintf(stderr, "ENOMEM\n");
    exit(1);
  }
  krb5_nfold(inlen, instr, outlen, outstr);
  printf("%d-fold(", outlen);
  for (i = 0; i < (inlen / 8); i++)
    printf("%02x", instr[i]);
  printf(") = ");
  for (i = 0; i < (outlen / 8); i++)
    printf("%02x", outstr[i]);
  printf("\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
shl    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1218 <main+0xa8>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1259 <main+0xe9>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1070 <krb5_nfold@plt>
mov    -0x18(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    12ca <main+0x15a>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1284 <main+0x114>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1325 <main+0x1b5>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12df <main+0x16f>
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    11df <main+0x5f>
mov    0x8(%rbp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
test   $0x7,%r15b
jne    1204 <main+0x84>
lea    0x7(%r15),%ebp
test   %r15d,%r15d
cmovns %r15d,%ebp
sar    $0x3,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    1225 <main+0xa5>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
jmp    1214 <main+0x94>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%r14
mov    %ebp,0x4(%rsp)
lea    0x0(,%rbx,8),%edi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %rax,%rcx
call   1080 <krb5_nfold@plt>
lea    0xdf2(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1288 <main+0x108>
mov    %ebx,%ebx
lea    0xde4(%rip),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%r13,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%rbx
jne    1270 <main+0xf0>
lea    0xdb9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x8,%r15d
jl     12c8 <main+0x148>
mov    0x4(%rsp),%ebp
lea    0xd9c(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12b0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s: instr outlen\0A\00"
@.str.1 = [32 x i8] c"outlen must be a multiple of 8\0A\00"
@.str.2 = [8 x i8] c"ENOMEM\0A\00"
@.str.3 = [9 x i8] c"%d-fold(\00"
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [5 x i8] c") = \00"
@.str.6 = [2 x i8] c"\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 i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = call i32 @strlen(i8* %24)
%26 = mul nsw i32 %25, 8
store i32 %26, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = srem i32 %31, 8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %20
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %20
%39 = load i32, i32* %7
%40 = sdiv i32 %39, 8
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %10
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = load i32, i32* %6
%50 = load i8*, i8** %9
%51 = load i32, i32* %7
%52 = load i8*, i8** %10
%53 = call i32 @krb5_nfold(i32 %49, i8* %50, i32 %51, i8* %52)
%54 = load i32, i32* %7
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %54)
store i32 0, i32* %8
br label %56
56: ; preds = %69, %48
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = sdiv i32 %58, 8
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %72
61: ; preds = %56
%62 = load i8*, i8** %9
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %61
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %56
72: ; preds = %56
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %74
74: ; preds = %87, %72
%75 = load i32, i32* %8
%76 = load i32, i32* %7
%77 = sdiv i32 %76, 8
%78 = icmp slt i32 %75, %77
br i1 %78, label %79, label %90
79: ; preds = %74
%80 = load i8*, i8** %10
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %79
%88 = load i32, i32* %8
%89 = add nsw i32 %88, 1
store i32 %89, i32* %8
br label %74
90: ; preds = %74
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%92 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s: instr outlen\0A\00"
@.str.1 = [32 x i8] c"outlen must be a multiple of 8\0A\00"
@.str.2 = [8 x i8] c"ENOMEM\0A\00"
@.str.3 = [9 x i8] c"%d-fold(\00"
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [5 x i8] c") = \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = shl nsw i32 %12, 3
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = and i32 %16, 7
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %9
%24 = sdiv i32 %16, 8
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = tail call i32 @krb5_nfold(i32 %13, i8* %11, i32 %16, i8* %26)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%35 = icmp sgt i32 %12, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = zext i32 %12 to i64
br label %38
38: ; preds = %36, %38
%39 = phi i64 [ 0, %36 ], [ %44, %38 ]
%40 = getelementptr inbounds i8, i8* %11, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %39, 1
%45 = icmp eq i64 %44, %37
br i1 %45, label %46, label %38
46: ; preds = %38, %32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp sgt i32 %16, 7
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = zext i32 %24 to i64
br label %51
51: ; preds = %49, %51
%52 = phi i64 [ 0, %49 ], [ %57, %51 ]
%53 = getelementptr inbounds i8, i8* %26, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = add nuw nsw i64 %52, 1
%58 = icmp eq i64 %57, %50
br i1 %58, label %59, label %51
59: ; preds = %51, %46
%60 = tail call i32 @putchar(i32 10)
%61 = tail call i32 @exit(i32 0)
unreachable
}