#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int decimal;
  bool negative = false;
  printf("请输入一个十进制数: ");
  scanf("%d", &decimal);
  if (decimal < 0) {
    negative = true;
    decimal *= -1;
  }
  int i, num[10];
  for (i = 0; i < 10 && decimal != 0; i++) {
    num[i] = decimal % 16;
    decimal /= 16;
  }
  printf("转换成十六进制为: %c0x", negative ? '-' : ' ');
  int j;
  for (j = i; j > 0; j--) {
    switch (num[j - 1]) {
    case 10:
      printf("a");
      break;
    case 11:
      printf("b");
      break;
    case 12:
      printf("c");
      break;
    case 13:
      printf("d");
      break;
    case 14:
      printf("e");
      break;
    case 15:
      printf("f");
      break;
    default:
      printf("%d", num[j - 1]);
      break;
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    116c <main+0x4c>
movl   $0x1,-0xc(%rbp)
imul   $0xffffffff,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x45(%rbp)
jge    118c <main+0x6c>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    119c <main+0x7c>
jmp    11cb <main+0xab>
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq -0x10(%rbp),%rax
mov    %edx,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1173 <main+0x53>
mov    -0xc(%rbp),%ecx
mov    $0x20,%esi
mov    $0x2d,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    12cd <main+0x1ad>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
cltq
mov    -0x40(%rbp,%rax,4),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x5,%eax
ja     12a0 <main+0x180>
mov    -0x50(%rbp),%rax
lea    0xddb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%esi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bf <main+0x19f>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    11f2 <main+0xd2>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
test   %eax,%eax
js     118d <main+0x5d>
jne    118f <main+0x5f>
lea    0xece(%rip),%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
neg    %ecx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsi
lea    0xf(%rcx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
mov    %edx,%edi
and    $0xfffffff0,%edi
mov    %ecx,%ebx
sub    %edi,%ebx
mov    %ebx,0x10(%rsp,%rsi,4)
sar    $0x4,%edx
lea    0x1(%rsi),%rbx
cmp    $0x8,%rsi
ja     11cf <main+0x9f>
add    $0xfffffff0,%ecx
cmp    $0xffffffe1,%ecx
mov    %edx,%ecx
jb     11a0 <main+0x70>
test   %eax,%eax
mov    %edx,0xc(%rsp)
mov    $0x2d,%eax
mov    $0x20,%esi
cmovs  %eax,%esi
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
lea    0xe3b(%rip),%r14
lea    0xdfe(%rip),%r15
jmp    121e <main+0xee>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    1177 <main+0x47>
mov    0x8(%rsp,%rbx,4),%esi
lea    -0xa(%rsi),%eax
cmp    $0x5,%eax
ja     1204 <main+0xd4>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x61,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>
mov    $0x62,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>
mov    $0x63,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>
mov    $0x64,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>
mov    $0x65,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>
mov    $0x66,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xe0>

LLVM IR (-O0):
@.str = [30 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E5\8D\81\E8\BF\9B\E5\88\B6\E6\95\B0: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"\E8\BD\AC\E6\8D\A2\E6\88\90\E5\8D\81\E5\85\AD\E8\BF\9B\E5\88\B6\E4\B8\BA: %c0x\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [2 x i8] c"b\00"
@.str.5 = [2 x i8] c"c\00"
@.str.6 = [2 x i8] c"d\00"
@.str.7 = [2 x i8] c"e\00"
@.str.8 = [2 x i8] c"f\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i32]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
store i32 1, i32* %3
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, -1
store i32 %13, i32* %2
br label %14
14: ; preds = %11, %0
store i32 0, i32* %4
br label %15
15: ; preds = %31, %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ false, %15 ], [ %20, %18 ]
br i1 %22, label %23, label %34
23: ; preds = %21
%24 = load i32, i32* %2
%25 = srem i32 %24, 16
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %27
store i32 %25, i32* %28
%29 = load i32, i32* %2
%30 = sdiv i32 %29, 16
store i32 %30, i32* %2
br label %31
31: ; preds = %23
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %15
34: ; preds = %21
%35 = load i32, i32* %3
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 45, i32 32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %4
store i32 %40, i32* %6
br label %41
41: ; preds = %70, %34
%42 = load i32, i32* %6
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %73
44: ; preds = %41
%45 = load i32, i32* %6
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %47
%49 = load i32, i32* %48
switch i32 %49, label %62 [
i32 10, label %50
i32 11, label %52
i32 12, label %54
i32 13, label %56
i32 14, label %58
i32 15, label %60
]
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %69
52: ; preds = %44
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %69
54: ; preds = %44
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %69
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %69
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %69
60: ; preds = %44
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %69
62: ; preds = %44
%63 = load i32, i32* %6
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %62, %60, %58, %56, %54, %52, %50
br label %70
70: ; preds = %69
%71 = load i32, i32* %6
%72 = add nsw i32 %71, -1
store i32 %72, i32* %6
br label %41
73: ; preds = %41
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E5\8D\81\E8\BF\9B\E5\88\B6\E6\95\B0: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"\E8\BD\AC\E6\8D\A2\E6\88\90\E5\8D\81\E5\85\AD\E8\BF\9B\E5\88\B6\E4\B8\BA: %c0x\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = sub nsw i32 0, %6
%10 = bitcast [10 x i32]* %2 to i8*
br label %14
11: ; preds = %0
%12 = bitcast [10 x i32]* %2 to i8*
%13 = icmp eq i32 %6, 0
br i1 %13, label %27, label %14
14: ; preds = %8, %11
%15 = phi i32 [ %6, %11 ], [ %9, %8 ]
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %22, %16 ], [ 0, %14 ]
%18 = phi i32 [ %21, %16 ], [ %15, %14 ]
%19 = srem i32 %18, 16
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %17
store i32 %19, i32* %20
%21 = sdiv i32 %18, 16
%22 = add nuw nsw i64 %17, 1
%23 = icmp ult i64 %17, 9
%24 = add i32 %18, -16
%25 = icmp ult i32 %24, -31
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %16, label %29
27: ; preds = %11
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 32)
br label %54
29: ; preds = %16
store i32 %21, i32* %1
%30 = select i1 %7, i32 45, i32 32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = and i64 %22, 4294967295
br label %33
33: ; preds = %29, %52
%34 = phi i64 [ %32, %29 ], [ %35, %52 ]
%35 = add nsw i64 %34, -1
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
switch i32 %37, label %50 [
i32 10, label %38
i32 11, label %40
i32 12, label %42
i32 13, label %44
i32 14, label %46
i32 15, label %48
]
38: ; preds = %33
%39 = call i32 @putchar(i32 97)
br label %52
40: ; preds = %33
%41 = call i32 @putchar(i32 98)
br label %52
42: ; preds = %33
%43 = call i32 @putchar(i32 99)
br label %52
44: ; preds = %33
%45 = call i32 @putchar(i32 100)
br label %52
46: ; preds = %33
%47 = call i32 @putchar(i32 101)
br label %52
48: ; preds = %33
%49 = call i32 @putchar(i32 102)
br label %52
50: ; preds = %33
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %52
52: ; preds = %38, %40, %42, %44, %46, %48, %50
%53 = icmp ugt i64 %34, 1
br i1 %53, label %33, label %54
54: ; preds = %52, %27
%55 = bitcast [10 x i32]* %2 to i8*
%56 = call i32 @putchar(i32 10)
ret i32 0
}