#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*/ nrerror(char *);
scalar_t__ space(int);
scalar_t__ strlen(char const *);
char *pack_structure(const char *struc) {
  int i, j, l, pi;
  unsigned char *packed;
  l = (int)strlen(struc);
  packed = (unsigned char *)space(((l + 4) / 5 + 1) * sizeof(unsigned char));
  j = i = pi = 0;
  while (i < l) {
    register int p;
    for (p = pi = 0; pi < 5; pi++) {
      p *= 3;
      switch (struc[i]) {
      case '(':
      case '\0':
        break;
      case '.':
        p++;
        break;
      case ')':
        p += 2;
        break;
      default:
        nrerror("pack_structure: illegal charcter in structure");
      }
      if (i < l)
        i++;
    }
    packed[j++] = (unsigned char)(p + 1);
  }
  packed[j] = '\0';
  return (char *)packed;
}


x86 assembly (clang, -O0):
<pack_structure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <space@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1274 <pack_structure+0x144>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    1252 <pack_structure+0x122>
mov    -0x24(%rbp),%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     11fd <pack_structure+0xcd>
jmp    11ca <pack_structure+0x9a>
mov    -0x28(%rbp),%eax
sub    $0x28,%eax
je     11fd <pack_structure+0xcd>
jmp    11db <pack_structure+0xab>
mov    -0x28(%rbp),%eax
sub    $0x29,%eax
je     1210 <pack_structure+0xe0>
jmp    11ec <pack_structure+0xbc>
mov    -0x28(%rbp),%eax
sub    $0x2e,%eax
je     1202 <pack_structure+0xd2>
jmp    121e <pack_structure+0xee>
jmp    122a <pack_structure+0xfa>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122a <pack_structure+0xfa>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    122a <pack_structure+0xfa>
lea    0xddb(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123f <pack_structure+0x10f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1244 <pack_structure+0x114>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <pack_structure+0x69>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    117f <pack_structure+0x4f>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_structure>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
call   1050 <strlen@plt>
mov    %rax,%r13
add    $0x4,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
sar    $0x21,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%edi
add    $0x1,%edi
call   1030 <space@plt>
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
test   %r13d,%r13d
jle    13e9 <pack_structure+0x2b9>
xor    %r15d,%r15d
mov    0x8(%rsp),%rcx
jmp    11c7 <pack_structure+0x97>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %r12d,%r12d
cmp    %r13d,%ebx
setl   %r12b
add    %ebx,%r12d
add    $0x1,%bpl
mov    0x10(%rsp),%rax
mov    %bpl,(%rax,%r15,1)
add    $0x1,%r15
cmp    %r13d,%r12d
jge    13e6 <pack_structure+0x2b6>
movslq %r12d,%rax
movsbl (%rcx,%rax,1),%eax
xor    %ebp,%ebp
cmp    $0x28,%eax
jg     11e0 <pack_structure+0xb0>
test   %eax,%eax
je     1230 <pack_structure+0x100>
cmp    $0x28,%eax
je     1230 <pack_structure+0x100>
jmp    1210 <pack_structure+0xe0>
cmp    $0x29,%eax
je     1200 <pack_structure+0xd0>
cmp    $0x2e,%eax
jne    1210 <pack_structure+0xe0>
mov    $0x3,%ebp
jmp    1230 <pack_structure+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x6,%ebp
jmp    1230 <pack_structure+0x100>
nopw   0x0(%rax,%rax,1)
lea    0xde9(%rip),%rdi
call   1040 <nrerror@plt>
mov    0x8(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
cmp    %r13d,%r12d
setl   %r14b
add    %r12d,%r14d
movslq %r14d,%rax
movsbl (%rcx,%rax,1),%eax
cmp    $0x28,%eax
jg     1260 <pack_structure+0x130>
test   %eax,%eax
je     12a0 <pack_structure+0x170>
cmp    $0x28,%eax
je     12a0 <pack_structure+0x170>
jmp    1280 <pack_structure+0x150>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x2e,%eax
je     1270 <pack_structure+0x140>
cmp    $0x29,%eax
jne    1280 <pack_structure+0x150>
add    $0x2,%ebp
jmp    12a0 <pack_structure+0x170>
nop
add    $0x1,%ebp
jmp    12a0 <pack_structure+0x170>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xd79(%rip),%rdi
call   1040 <nrerror@plt>
mov    0x8(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cmp    %r13d,%r14d
setl   %bl
add    %r14d,%ebx
lea    0x0(%rbp,%rbp,2),%r14d
movslq %ebx,%rax
movsbl (%rcx,%rax,1),%eax
cmp    $0x28,%eax
jg     12d0 <pack_structure+0x1a0>
test   %eax,%eax
je     1310 <pack_structure+0x1e0>
cmp    $0x28,%eax
je     1310 <pack_structure+0x1e0>
jmp    12f0 <pack_structure+0x1c0>
nopw   0x0(%rax,%rax,1)
cmp    $0x2e,%eax
je     12e0 <pack_structure+0x1b0>
cmp    $0x29,%eax
jne    12f0 <pack_structure+0x1c0>
add    $0x2,%r14d
jmp    1310 <pack_structure+0x1e0>
add    $0x1,%r14d
jmp    1310 <pack_structure+0x1e0>
cs nopw 0x0(%rax,%rax,1)
lea    0xd09(%rip),%rdi
call   1040 <nrerror@plt>
mov    0x8(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cmp    %r13d,%ebx
setl   %bpl
add    %ebx,%ebp
lea    (%r14,%r14,2),%r14d
movslq %ebp,%rax
movsbl (%rcx,%rax,1),%eax
cmp    $0x28,%eax
jg     1340 <pack_structure+0x210>
test   %eax,%eax
je     1380 <pack_structure+0x250>
cmp    $0x28,%eax
je     1380 <pack_structure+0x250>
jmp    1360 <pack_structure+0x230>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x2e,%eax
je     1350 <pack_structure+0x220>
cmp    $0x29,%eax
jne    1360 <pack_structure+0x230>
add    $0x2,%r14d
jmp    1380 <pack_structure+0x250>
add    $0x1,%r14d
jmp    1380 <pack_structure+0x250>
cs nopw 0x0(%rax,%rax,1)
lea    0xc99(%rip),%rdi
call   1040 <nrerror@plt>
mov    0x8(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cmp    %r13d,%ebp
setl   %bl
add    %ebp,%ebx
lea    (%r14,%r14,2),%ebp
movslq %ebx,%rax
movsbl (%rcx,%rax,1),%eax
cmp    $0x28,%eax
jg     13b0 <pack_structure+0x280>
test   %eax,%eax
je     11a0 <pack_structure+0x70>
cmp    $0x28,%eax
je     11a0 <pack_structure+0x70>
jmp    13d0 <pack_structure+0x2a0>
nopl   (%rax)
cmp    $0x2e,%eax
je     1190 <pack_structure+0x60>
cmp    $0x29,%eax
jne    13d0 <pack_structure+0x2a0>
add    $0x2,%ebp
jmp    11a0 <pack_structure+0x70>
cs nopw 0x0(%rax,%rax,1)
lea    0xc29(%rip),%rdi
call   1040 <nrerror@plt>
mov    0x8(%rsp),%rcx
jmp    11a0 <pack_structure+0x70>
mov    %r15d,%r12d
mov    0x10(%rsp),%rax
movb   $0x0,(%rax,%r12,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"pack_structure: illegal charcter in structure\00"
define i8* @pack_structure(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 4
%14 = sdiv i32 %13, 5
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i64 @space(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %7
store i32 0, i32* %6
store i32 0, i32* %3
store i32 0, i32* %4
br label %21
21: ; preds = %58, %1
%22 = load i32, i32* %3
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %67
25: ; preds = %21
store i32 0, i32* %6
store i32 0, i32* %8
br label %26
26: ; preds = %55, %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %58
29: ; preds = %26
%30 = load i32, i32* %8
%31 = mul nsw i32 %30, 3
store i32 %31, i32* %8
%32 = load i8*, i8** %2
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %45 [
i32 40, label %38
i32 0, label %38
i32 46, label %39
i32 41, label %42
]
38: ; preds = %29, %29
br label %47
39: ; preds = %29
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %47
42: ; preds = %29
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 2
store i32 %44, i32* %8
br label %47
45: ; preds = %29
%46 = call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %45, %42, %39, %38
%48 = load i32, i32* %3
%49 = load i32, i32* %5
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %54
54: ; preds = %51, %47
br label %55
55: ; preds = %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %26
58: ; preds = %26
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
%61 = trunc i32 %60 to i8
%62 = load i8*, i8** %7
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 %61, i8* %66
br label %21
67: ; preds = %21
%68 = load i8*, i8** %7
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 0, i8* %71
%72 = load i8*, i8** %7
ret i8* %72
}

LLVM IR (-O2):
@.str = [46 x i8] c"pack_structure: illegal charcter in structure\00"
define i8* @pack_structure(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add nsw i32 %3, 4
%5 = sdiv i32 %4, 5
%6 = add nsw i32 %5, 1
%7 = tail call i64 @space(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %96
10: ; preds = %1, %84
%11 = phi i64 [ %91, %84 ], [ 0, %1 ]
%12 = phi i32 [ %88, %84 ], [ 0, %1 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %19 [
i32 40, label %21
i32 0, label %21
i32 46, label %17
i32 41, label %18
]
17: ; preds = %10
br label %21
18: ; preds = %10
br label %21
19: ; preds = %10
%20 = tail call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %10, %10, %19, %18, %17
%22 = phi i32 [ 0, %19 ], [ 6, %18 ], [ 3, %17 ], [ 0, %10 ], [ 0, %10 ]
%23 = icmp slt i32 %12, %3
%24 = zext i1 %23 to i32
%25 = add nsw i32 %12, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %34 [
i32 40, label %36
i32 0, label %36
i32 46, label %32
i32 41, label %30
]
30: ; preds = %21
%31 = add nuw nsw i32 %22, 2
br label %36
32: ; preds = %21
%33 = add nuw nsw i32 %22, 1
br label %36
34: ; preds = %21
%35 = tail call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %32, %30, %21, %21
%37 = phi i32 [ %22, %34 ], [ %31, %30 ], [ %33, %32 ], [ %22, %21 ], [ %22, %21 ]
%38 = icmp slt i32 %25, %3
%39 = zext i1 %38 to i32
%40 = add nsw i32 %25, %39
%41 = mul nuw nsw i32 %37, 3
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
switch i32 %45, label %50 [
i32 40, label %52
i32 0, label %52
i32 46, label %48
i32 41, label %46
]
46: ; preds = %36
%47 = add nuw nsw i32 %41, 2
br label %52
48: ; preds = %36
%49 = add nuw nsw i32 %41, 1
br label %52
50: ; preds = %36
%51 = tail call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %50, %48, %46, %36, %36
%53 = phi i32 [ %41, %50 ], [ %47, %46 ], [ %49, %48 ], [ %41, %36 ], [ %41, %36 ]
%54 = icmp slt i32 %40, %3
%55 = zext i1 %54 to i32
%56 = add nsw i32 %40, %55
%57 = mul nuw nsw i32 %53, 3
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
switch i32 %61, label %66 [
i32 40, label %68
i32 0, label %68
i32 46, label %64
i32 41, label %62
]
62: ; preds = %52
%63 = add nuw nsw i32 %57, 2
br label %68
64: ; preds = %52
%65 = add nuw nsw i32 %57, 1
br label %68
66: ; preds = %52
%67 = tail call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %68
68: ; preds = %66, %64, %62, %52, %52
%69 = phi i32 [ %57, %66 ], [ %63, %62 ], [ %65, %64 ], [ %57, %52 ], [ %57, %52 ]
%70 = icmp slt i32 %56, %3
%71 = zext i1 %70 to i32
%72 = add nsw i32 %56, %71
%73 = mul nuw nsw i32 %69, 3
%74 = sext i32 %72 to i64
%75 = getelementptr inbounds i8, i8* %0, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
switch i32 %77, label %82 [
i32 40, label %84
i32 0, label %84
i32 46, label %80
i32 41, label %78
]
78: ; preds = %68
%79 = add nuw nsw i32 %73, 2
br label %84
80: ; preds = %68
%81 = add nuw nsw i32 %73, 1
br label %84
82: ; preds = %68
%83 = tail call i32 @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %84
84: ; preds = %82, %80, %78, %68, %68
%85 = phi i32 [ %73, %82 ], [ %79, %78 ], [ %81, %80 ], [ %73, %68 ], [ %73, %68 ]
%86 = icmp slt i32 %72, %3
%87 = zext i1 %86 to i32
%88 = add nsw i32 %72, %87
%89 = trunc i32 %85 to i8
%90 = add nuw i8 %89, 1
%91 = add nuw i64 %11, 1
%92 = getelementptr inbounds i8, i8* %8, i64 %11
store i8 %90, i8* %92
%93 = icmp slt i32 %88, %3
br i1 %93, label %10, label %94
94: ; preds = %84
%95 = and i64 %91, 4294967295
br label %96
96: ; preds = %94, %1
%97 = phi i64 [ 0, %1 ], [ %95, %94 ]
%98 = getelementptr inbounds i8, i8* %8, i64 %97
store i8 0, i8* %98
ret i8* %8
}