#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
void sprint_opcode(char *str, uint8_t *IR) {
  if (IR[3] > 0)
    sprintf(str, "%02X", IR[0]);
  if (IR[3] > 1)
    sprintf(str, "%02X", IR[1]);
  if (IR[3] > 2)
    sprintf(str, "%02X", IR[2]);
}


x86 assembly (clang, -O0):
<sprint_opcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0xc(%rax)
jle    1144 <sprint_opcode+0x34>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xec1(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x1,0xc(%rax)
jle    1169 <sprint_opcode+0x59>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe9c(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2,0xc(%rax)
jle    118e <sprint_opcode+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe77(%rip),%rsi
call   1030 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_opcode>:
push   %r14
push   %rbx
push   %rax
cmpl   $0x0,0xc(%rsi)
jle    1165 <sprint_opcode+0x55>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edx
lea    0xed7(%rip),%rsi
call   1030 <sprintf@plt>
cmpl   $0x2,0xc(%rbx)
jl     1165 <sprint_opcode+0x55>
mov    0x4(%rbx),%edx
lea    0xec2(%rip),%rsi
mov    %r14,%rdi
call   1030 <sprintf@plt>
cmpl   $0x3,0xc(%rbx)
jl     1165 <sprint_opcode+0x55>
mov    0x8(%rbx),%edx
lea    0xeaa(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <sprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @sprint_opcode(i8* nocapture writeonly %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 3
%4 = load i32, i32* %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = load i32, i32* %1
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = getelementptr inbounds i32, i32* %1, i64 1
%13 = load i32, i32* %12
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = getelementptr inbounds i32, i32* %1, i64 2
%19 = load i32, i32* %18
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %2, %6, %17, %11
ret void
}