#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 divide(int numerator, int denominator, int n) {
  printf("%d/%d = %d.", numerator, denominator, numerator / denominator);
  int left = (numerator % denominator) * 10;
  while (n--) {
    printf("%d", left / denominator);
    left = (left % denominator) * 10;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<divide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
imul   $0xa,%edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     118e <divide+0x7e>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
imul   $0xa,%edx,%eax
mov    %eax,-0x10(%rbp)
jmp    1151 <divide+0x41>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<divide>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %edi,%eax
cltd
idiv   %esi
lea    0xec6(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     1182 <divide+0x62>
lea    0xeb9(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%eax
cltd
idiv   %r14d
add    %edx,%edx
lea    (%rdx,%rdx,4),%ebp
mov    %ebp,%eax
cltd
idiv   %r14d
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
jne    1160 <divide+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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