#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 */
struct soap {
  int dummy;
};

/* Variables and functions */
int soap_send(struct soap *, char *);
int soap_puthex(struct soap *soap, int n) {
  char d[3];
  d[0] = (n >> 4) + (n > 159 ? '7' : '0');
  n &= 0x0F;
  d[1] = n + (n > 9 ? '7' : '0');
  d[2] = '\0';
  return soap_send(soap, d);
}


x86 assembly (clang, -O0):
<soap_puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    -0xc(%rbp),%esi
mov    $0x30,%ecx
mov    $0x37,%edx
cmp    $0x9f,%esi
cmovg  %edx,%ecx
add    %ecx,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%esi
mov    $0x30,%ecx
mov    $0x37,%edx
cmp    $0x9,%esi
cmovg  %edx,%ecx
add    %ecx,%eax
mov    %al,-0xe(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
call   1030 <soap_send@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soap_puthex>:
push   %rax
mov    %esi,%eax
shr    $0x4,%eax
lea    0x30(%rax),%ecx
add    $0x37,%eax
cmp    $0xa0,%esi
cmovl  %ecx,%eax
mov    %al,0x5(%rsp)
and    $0xf,%esi
lea    0x30(%rsi),%eax
lea    0x37(%rsi),%ecx
cmp    $0xa,%esi
cmovb  %eax,%ecx
mov    %cl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x5(%rsp),%rsi
call   1030 <soap_send@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.soap = type { i32 }
define i32 @soap_puthex(%struct.soap* %0, i32 %1) {
%3 = alloca %struct.soap*
%4 = alloca i32
%5 = alloca [3 x i8]
store %struct.soap* %0, %struct.soap** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = ashr i32 %6, 4
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 159
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 55, i32 48
%12 = add nsw i32 %7, %11
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i32, i32* %4
%16 = and i32 %15, 15
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 9
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 55, i32 48
%22 = add nsw i32 %17, %21
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %23, i8* %24
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %25
%26 = load %struct.soap*, %struct.soap** %3
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%28 = call i32 @soap_send(%struct.soap* %26, i8* %27)
ret i32 %28
}

LLVM IR (-O2):
%struct.soap = type { i32 }
define i32 @soap_puthex(%struct.soap* %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = lshr i32 %1, 4
%6 = icmp sgt i32 %1, 159
%7 = select i1 %6, i32 55, i32 48
%8 = add nuw nsw i32 %7, %5
%9 = trunc i32 %8 to i8
store i8 %9, i8* %4
%10 = and i32 %1, 15
%11 = icmp ugt i32 %10, 9
%12 = select i1 %11, i32 55, i32 48
%13 = add nuw nsw i32 %12, %10
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %14, i8* %15
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %16
%17 = call i32 @soap_send(%struct.soap* %0, i8* %4)
ret i32 %17
}