#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 uint32_t;

/* Variables and functions */
unsigned char *asciihex2hexbytes(int *, unsigned char *);
unsigned char *break_shiftcipher(int, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int strlen(unsigned char *);
int main(int argc, char *argv[]) {
  unsigned char instring[] =
      "7b5a4215415d544115415d5015455447414c155c46155f4058455c5b523f";
  uint32_t inlen = strlen(instring);
  unsigned char *hb, *plain;
  hb = asciihex2hexbytes(&inlen, instring);
  printf("input: ");
  for (int i = 0; i < inlen; i++)
    printf("%x", hb[i]);
  puts("");
  plain = break_shiftcipher(inlen, hb);
  printf("output: ");
  for (int i = 0; i < inlen; i++)
    printf("%c", plain[i]);
  puts("");
  return 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)
lea    -0x50(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x3d,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rsi
lea    -0x54(%rbp),%rdi
call   1080 <asciihex2hexbytes@plt>
mov    %rax,-0x60(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    11f1 <main+0x91>
mov    -0x60(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11bd <main+0x5d>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    -0x54(%rbp),%edi
mov    -0x60(%rbp),%rsi
call   1070 <break_shiftcipher@plt>
mov    %rax,-0x68(%rbp)
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    1256 <main+0xf6>
mov    -0x68(%rbp),%rax
movslq -0x70(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1222 <main+0xc2>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
movups 0xecd(%rip),%xmm0
movups %xmm0,0x3d(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <asciihex2hexbytes@plt>
mov    %rax,%r15
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ed <main+0x9d>
lea    0xe7f(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
call   1060 <break_shiftcipher@plt>
mov    %rax,%r14
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1238 <main+0xe8>
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r14,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.instring = [61 x i8] c"7b5a4215415d544115415d5015455447414c155c46155f4058455c5b523f\00"
@.str = [8 x i8] c"input: \00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [9 x i8] c"output: \00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [61 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [61 x i8]* %6 to i8*
%13 = getelementptr inbounds [61 x i8], [61 x i8]* %6, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
%15 = getelementptr inbounds [61 x i8], [61 x i8]* %6, i64 0, i64 0
%16 = call i8* @asciihex2hexbytes(i32* %7, i8* %15)
store i8* %16, i8** %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %18
18: ; preds = %30, %2
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
br label %18
33: ; preds = %18
%34 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* %7
%36 = load i8*, i8** %8
%37 = call i8* @break_shiftcipher(i32 %35, i8* %36)
store i8* %37, i8** %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %11
br label %39
39: ; preds = %51, %33
%40 = load i32, i32* %11
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %54
43: ; preds = %39
%44 = load i8*, i8** %9
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %43
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %39
54: ; preds = %39
%55 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.instring = [61 x i8] c"7b5a4215415d544115415d5015455447414c155c46155f4058455c5b523f\00"
@.str = [8 x i8] c"input: \00"
@.str.1 = [3 x i8] c"%x\00"
@.str.3 = [9 x i8] c"output: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [61 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i32 @strlen(i8* %5)
store i32 %7, i32* %4
%8 = call i8* @asciihex2hexbytes(i32* %4, i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %19, %2
%13 = call i32 @putchar(i32 10)
%14 = load i32, i32* %4
%15 = call i8* @break_shiftcipher(i32 %14, i8* %8)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %31, label %29
19: ; preds = %2, %19
%20 = phi i64 [ %25, %19 ], [ 0, %2 ]
%21 = getelementptr inbounds i8, i8* %8, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %20, 1
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %19, label %12
29: ; preds = %31, %12
%30 = call i32 @putchar(i32 10)
ret i32 0
31: ; preds = %12, %31
%32 = phi i64 [ %37, %31 ], [ 0, %12 ]
%33 = getelementptr inbounds i8, i8* %15, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 @putchar(i32 %35)
%37 = add nuw nsw i64 %32, 1
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %31, label %29
}