#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 from_hex(char);
unsigned char gsm2ascii(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void show_string(char *buffer) {
  unsigned char raw[1024];
  int i;
  int len = strlen(buffer);
  if (len % 2 != 0) {
    printf("Bad data length!\n");
    return;
  }
  len >>= 1;
  for (i = 0; i < len; i++)
    raw[i] = (from_hex(buffer[2 * i]) << 4) + from_hex(buffer[2 * i + 1]);
  for (i = 0; i < len; i++)
    raw[i] = gsm2ascii(raw[i]);
  raw[len] = '\0';
  printf("%s\n", raw);
}


x86 assembly (clang, -O0):
<show_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1188 <show_string+0x48>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1297 <show_string+0x157>
mov    -0x418(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x418(%rbp)
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x418(%rbp),%eax
jge    121f <show_string+0xdf>
mov    -0x8(%rbp),%rax
mov    -0x414(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <from_hex@plt>
shl    $0x4,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x414(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <from_hex@plt>
mov    %eax,%ecx
mov    -0x41c(%rbp),%eax
add    %ecx,%eax
mov    %al,%cl
movslq -0x414(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11a1 <show_string+0x61>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x418(%rbp),%eax
jge    1273 <show_string+0x133>
movslq -0x414(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%edi
ff
call   1050 <gsm2ascii@plt>
mov    %al,%cl
movslq -0x414(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1229 <show_string+0xe9>
movslq -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%r14d
test   $0x1,%r14b
jne    1206 <show_string+0xc6>
mov    %r14d,%r15d
sar    %r15d
cmp    $0x2,%r14d
jl     11e5 <show_string+0xa5>
cmp    $0x2,%r15d
mov    $0x1,%r12d
cmovge %r15d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x0(%r13,%rbx,2),%edi
call   1060 <from_hex@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%r13,%rbx,2),%edi
call   1060 <from_hex@plt>
add    %ebp,%eax
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <show_string+0x50>
cmp    $0x2,%r14d
jl     11e5 <show_string+0xa5>
cmp    $0x2,%r15d
mov    $0x1,%ebx
cmovge %r15d,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl (%rsp,%rbp,1),%edi
call   1050 <gsm2ascii@plt>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <show_string+0x90>
movslq %r15d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <puts@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf3(%rip),%rdi
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Bad data length!\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @show_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = srem i32 %8, 2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %68
13: ; preds = %1
%14 = load i32, i32* %5
%15 = ashr i32 %14, 1
store i32 %15, i32* %5
store i32 0, i32* %4
br label %16
16: ; preds = %42, %13
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = mul nsw i32 2, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @from_hex(i8 signext %26)
%28 = shl i32 %27, 4
%29 = load i8*, i8** %2
%30 = load i32, i32* %4
%31 = mul nsw i32 2, %30
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @from_hex(i8 signext %35)
%37 = add nsw i32 %28, %36
%38 = trunc i32 %37 to i8
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %20
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %16
45: ; preds = %16
store i32 0, i32* %4
br label %46
46: ; preds = %59, %45
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %62
50: ; preds = %46
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = call zeroext i8 @gsm2ascii(i8 zeroext %54)
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %57
store i8 %55, i8* %58
br label %59
59: ; preds = %50
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %46
62: ; preds = %46
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %64
store i8 0, i8* %65
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %62, %11
ret void
}

LLVM IR (-O2):
@str = [17 x i8] c"Bad data length!\00"
define void @show_string(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %46
9: ; preds = %1
%10 = ashr i32 %4, 1
%11 = icmp sgt i32 %4, 1
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = call i32 @llvm.smax.i32(i32 %10, i32 1)
%14 = zext i32 %13 to i64
br label %19
15: ; preds = %19
br i1 %11, label %16, label %42
16: ; preds = %15
%17 = call i32 @llvm.smax.i32(i32 %10, i32 1)
%18 = zext i32 %17 to i64
br label %35
19: ; preds = %12, %19
%20 = phi i64 [ 0, %12 ], [ %33, %19 ]
%21 = shl nuw nsw i64 %20, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @from_hex(i8 signext %23)
%25 = shl i32 %24, 4
%26 = or i64 %21, 1
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = tail call i32 @from_hex(i8 signext %28)
%30 = add nsw i32 %29, %25
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %20
store i8 %31, i8* %32
%33 = add nuw nsw i64 %20, 1
%34 = icmp eq i64 %33, %14
br i1 %34, label %15, label %19
35: ; preds = %16, %35
%36 = phi i64 [ 0, %16 ], [ %40, %35 ]
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = tail call zeroext i8 @gsm2ascii(i8 zeroext %38)
store i8 %39, i8* %37
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, %18
br i1 %41, label %42, label %35
42: ; preds = %35, %9, %15
%43 = sext i32 %10 to i64
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %43
store i8 0, i8* %44
%45 = call i32 @puts(i8* %3)
br label %46
46: ; preds = %42, %7
ret void
}