#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 */
scalar_t__ log10(int);
int /*<<< orphan*/ printf(char *, ...);
int print_result(int num_digits, int num) {
  int num_blanks, i;
  num_blanks = (num == 0) ? num_digits - 1 : num_digits - (int)log10(num) - 1;
  for (i = 0; i < num_blanks; i++) {
    printf("0");
  }
  printf("%d\n", num);
}


x86 assembly (clang, -O0):
<print_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1146 <print_result+0x26>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <print_result+0x42>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <log10@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1197 <print_result+0x77>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <print_result+0x4f>
mov    -0xc(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_result>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
test   %esi,%esi
je     1175 <print_result+0x45>
mov    %ebx,%edi
call   1050 <log10@plt>
not    %eax
add    %ebp,%eax
mov    %eax,%ebp
test   %ebp,%ebp
jle    115f <print_result+0x2f>
nopl   0x0(%rax)
mov    $0x30,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1150 <print_result+0x20>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>
add    $0xffffffff,%ebp
test   %ebp,%ebp
jg     1150 <print_result+0x20>
jmp    115f <print_result+0x2f>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @print_result(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
br label %20
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i64 @log10(i32 %15)
%17 = trunc i64 %16 to i32
%18 = sub nsw i32 %14, %17
%19 = sub nsw i32 %18, 1
br label %20
20: ; preds = %13, %10
%21 = phi i32 [ %12, %10 ], [ %19, %13 ]
store i32 %21, i32* %6
store i32 0, i32* %7
br label %22
22: ; preds = %28, %20
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %22
31: ; preds = %22
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @print_result(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = add nsw i32 %0, -1
br label %11
6: ; preds = %2
%7 = tail call i64 @log10(i32 %1)
%8 = trunc i64 %7 to i32
%9 = xor i32 %8, -1
%10 = add i32 %9, %0
br label %11
11: ; preds = %6, %4
%12 = phi i32 [ %5, %4 ], [ %10, %6 ]
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11, %14
%15 = phi i32 [ %17, %14 ], [ 0, %11 ]
%16 = tail call i32 @putchar(i32 48)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, %12
br i1 %18, label %19, label %14
19: ; preds = %14, %11
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1)
ret i32 undef
}