#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 format(char *regname, int reg) {
  int i = 0;
  if (!reg)
    return;
  printf("%3s", regname);
  for (i = 31; i >= 0; i--)
    printf("%3x", reg & (1 << i) ? 1 : 0);
  printf("\n");
}


x86 assembly (clang, -O0):
<format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1135 <format+0x25>
jmp    11a4 <format+0x94>
mov    -0x8(%rbp),%rsi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1f,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1196 <format+0x86>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x14(%rbp),%ecx
and    %eax,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <format+0x3e>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
test   %esi,%esi
je     1176 <format+0x56>
mov    %rdi,%rsi
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1f,%ebp
lea    0xebd(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%esi
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jb     1150 <format+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%3s\00"
@.str.1 = [4 x i8] c"%3x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @format(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %2
br label %29
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 31, i32* %5
br label %12
12: ; preds = %24, %9
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = shl i32 1, %17
%19 = and i32 %16, %18
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %15
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %12
27: ; preds = %12
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %8
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%3s\00"
@.str.1 = [4 x i8] c"%3x\00"
define void @format(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %6
%7 = phi i32 [ 31, %4 ], [ %11, %6 ]
%8 = lshr i32 %1, %7
%9 = and i32 %8, 1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = add nsw i32 %7, -1
%12 = icmp eq i32 %7, 0
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = tail call i32 @putchar(i32 10)
br label %15
15: ; preds = %2, %13
ret void
}