#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 hex2(unsigned int x) {
  printf("hex2: %x\n", x);
  do {
    char c = "0123456789abcdef"[x & 0xf];
    printf("char %c for %d\n", c, x);
    x >>= 4;
    printf("char %c for %d\n", c, x);
  } while (x);
  printf("what!");
}


x86 assembly (clang, -O0):
<hex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xecd(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
movsbl -0x5(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jne    112c <hex2+0x1c>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
lea    0xedf(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed9(%rip),%r12
lea    0xee3(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%r15d
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%ebp
shr    $0x4,%ebp
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0xf,%ebx
mov    %ebp,%ebx
ja     1140 <hex2+0x30>
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"hex2: %x\0A\00"
@.str.1 = [17 x i8] c"0123456789abcdef\00"
@.str.2 = [16 x i8] c"char %c for %d\0A\00"
@.str.3 = [6 x i8] c"what!\00"
define void @hex2(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %22, %1
%7 = load i32, i32* %2
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %9
%11 = load i8, i8* %10
store i8 %11, i8* %3
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %2
%17 = lshr i32 %16, 4
store i32 %17, i32* %2
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %6
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %6, label %25
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"hex2: %x\0A\00"
@.str.1 = [17 x i8] c"0123456789abcdef\00"
@.str.2 = [16 x i8] c"char %c for %d\0A\00"
@.str.3 = [6 x i8] c"what!\00"
define void @hex2(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %3
3: ; preds = %3, %1
%4 = phi i32 [ %0, %1 ], [ %11, %3 ]
%5 = and i32 %4, 15
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %4)
%11 = lshr i32 %4, 4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %11)
%13 = icmp ult i32 %4, 16
br i1 %13, label %14, label %3
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret void
}