#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*/ printf(char *, ...);
void showmsg(char *txt, char nl, unsigned char *buf, int len) {
  int i, do_nl = 1;
  printf("%s%c", txt, nl);
  for (i = 1; i <= len; ++i) {
    printf("%02x ", *buf++);
    do_nl = 1;
    if (i % 16 == 0) {
      printf("\n");
      do_nl = 0;
    }
  }
  if (do_nl)
    printf("\n");
}


x86 assembly (clang, -O0):
<showmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
movsbl -0x9(%rbp),%edx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11bc <showmsg+0xac>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a9 <showmsg+0x99>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    11ae <showmsg+0x9e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114d <showmsg+0x3d>
cmpl   $0x0,-0x24(%rbp)
je     11d4 <showmsg+0xc4>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showmsg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %esi,%edx
mov    %rdi,%rsi
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1193 <showmsg+0x73>
mov    %ebp,%r12d
lea    0xeb7(%rip),%r14
xor    %ebx,%ebx
jmp    1169 <showmsg+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %ebx,%r12d
je     118d <showmsg+0x6d>
lea    0x1(%rbx),%ebp
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bpl
jne    1160 <showmsg+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <showmsg+0x40>
test   $0xf,%bpl
je     11a5 <showmsg+0x85>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%c\00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @showmsg(i8* %0, i8 signext %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 1, i32* %10
%11 = load i8*, i8** %5
%12 = load i8, i8* %6
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %13)
store i32 1, i32* %9
br label %15
15: ; preds = %31, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %7
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 1, i32* %10
%25 = load i32, i32* %9
%26 = srem i32 %25, 16
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %10
br label %30
30: ; preds = %28, %19
br label %31
31: ; preds = %30
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %15
34: ; preds = %15
%35 = load i32, i32* %10
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%c\00"
@.str.1 = [6 x i8] c"%02x \00"
define void @showmsg(i8* %0, i8 signext %1, i8* nocapture %2, i32 %3) {
%5 = sext i8 %1 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %5)
%7 = icmp slt i32 %3, 1
br i1 %7, label %23, label %8
8: ; preds = %4, %19
%9 = phi i32 [ %20, %19 ], [ 1, %4 ]
%10 = phi i8* [ %11, %19 ], [ %2, %4 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = zext i8 %12 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = and i32 %9, 15
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %8, %17
%20 = add nuw i32 %9, 1
%21 = icmp eq i32 %9, %3
br i1 %21, label %22, label %8
22: ; preds = %19
br i1 %16, label %25, label %23
23: ; preds = %4, %22
%24 = tail call i32 @putchar(i32 10)
br label %25
25: ; preds = %23, %22
ret void
}