#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 /*<<< orphan*/ encode(char *, size_t);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int main(void) {
  size_t i;
  size_t len;
  char buf[1024];
  fgets(buf, 1024, stdin);
  len = strlen(buf);
  encode(buf, len);
  printf("len: %u\n", len);
  for (i = 0; i < len; i++) {
    printf("0x%X ", buf[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x420(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <encode@plt>
mov    -0x18(%rbp),%rax
lea    0xe69(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11de <main+0x9e>
mov    -0x10(%rbp),%rax
lea    0xe49(%rip),%rdi
movsbl -0x420(%rbp,%rax,1),%esi
ff
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a7 <main+0x67>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <encode@plt>
movsbl %r15b,%esi
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
test   %r15,%r15
je     11b5 <main+0x75>
xor    %ebx,%ebx
lea    0xe70(%rip),%r14
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [9 x i8] c"len: %u\0A\00"
@.str.1 = [6 x i8] c"0x%X \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 1024, i32 %6)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = load i64, i64* %3
%12 = call i32 @encode(i8* %10, i64 %11)
%13 = load i64, i64* %3
%14 = trunc i64 %13 to i8
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %14)
store i64 0, i64* %2
br label %16
16: ; preds = %25, %0
%17 = load i64, i64* %2
%18 = load i64, i64* %3
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i64, i64* %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %23)
br label %25
25: ; preds = %20
%26 = load i64, i64* %2
%27 = add i64 %26, 1
store i64 %27, i64* %2
br label %16
28: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [9 x i8] c"len: %u\0A\00"
@.str.1 = [6 x i8] c"0x%X \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 1024, i32 %3)
%5 = call i64 @strlen(i8* %2)
%6 = call i32 @encode(i8* %2, i64 %5)
%7 = trunc i64 %5 to i8
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%9 = icmp eq i64 %5, 0
br i1 %9, label %17, label %10
10: ; preds = %0, %10
%11 = phi i64 [ %15, %10 ], [ 0, %0 ]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %13)
%15 = add nuw i64 %11, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %10
17: ; preds = %10, %0
ret i32 0
}