#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*/ Emit1(int);
int Hex(int);
void EmitString(const char *string) {
  int c1, c2;
  int v;
  while (1) {
    c1 = string[0];
    c2 = string[1];
    v = (Hex(c1) << 4) | Hex(c2);
    Emit1(v);
    if (!string[2]) {
      break;
    }
    string += 3;
  }
}


x86 assembly (clang, -O0):
<EmitString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <Hex@plt>
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <Hex@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <Emit1@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,0x2(%rax)
jne    117c <EmitString+0x5c>
jmp    118d <EmitString+0x6d>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <EmitString+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EmitString>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
movsbl 0x1(%rbx),%r14d
call   1040 <Hex@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
mov    %r14d,%edi
call   1040 <Hex@plt>
or     %eax,%ebp
mov    %ebp,%edi
call   1030 <Emit1@plt>
cmpb   $0x0,0x2(%rbx)
lea    0x3(%rbx),%rbx
jne    1130 <EmitString+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @EmitString(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %17, %2 ]
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = tail call i32 @Hex(i32 %5)
%10 = shl i32 %9, 4
%11 = tail call i32 @Hex(i32 %8)
%12 = or i32 %10, %11
%13 = tail call i32 @Emit1(i32 %12)
%14 = getelementptr inbounds i8, i8* %3, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
%17 = getelementptr inbounds i8, i8* %3, i64 3
br i1 %16, label %18, label %2
18: ; preds = %2
ret void
}