#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 CHAR_BIT;
int strlen(char *);
int pack_char_compact(char str[]) {
  int val = str[0];
  for (int i = 0; i < strlen(str); i++)
    val = (val << CHAR_BIT) | str[i];
  return val;
}


x86 assembly (clang, -O0):
<pack_char_compact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1176 <pack_char_compact+0x66>
mov    -0xc(%rbp),%eax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%ecx
shl    %cl,%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <pack_char_compact+0x1d>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_char_compact>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%ebx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1165 <pack_char_compact+0x55>
xor    %r15d,%r15d
mov    0x2eaf(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12),%ecx
shl    %cl,%ebx
movsbl (%r14,%r15,1),%ebp
or     %ebx,%ebp
add    $0x1,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
mov    %ebp,%ebx
cmp    %rax,%r15
jl     1140 <pack_char_compact+0x30>
jmp    1167 <pack_char_compact+0x57>
mov    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i32 @pack_char_compact(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
store i32 %8, i32* %3
store i32 0, i32* %4
br label %9
9: ; preds = %25, %1
%10 = load i32, i32* %4
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %28
14: ; preds = %9
%15 = load i32, i32* %3
%16 = load i32, i32* @CHAR_BIT
%17 = shl i32 %15, %16
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = or i32 %17, %23
store i32 %24, i32* %3
br label %25
25: ; preds = %14
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i32 @pack_char_compact(i8* %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %8, %1
%7 = phi i32 [ %3, %1 ], [ %16, %8 ]
ret i32 %7
8: ; preds = %1, %8
%9 = phi i64 [ %17, %8 ], [ 0, %1 ]
%10 = phi i32 [ %16, %8 ], [ %3, %1 ]
%11 = load i32, i32* @CHAR_BIT
%12 = shl i32 %10, %11
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = or i32 %12, %15
%17 = add nuw nsw i64 %9, 1
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %8, label %6
}