#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
main() {
  int divisor, dividend, quotient, remainder;
  int valid_input = 0;
  char inbuf[133];
  while (valid_input < 1) {
    printf("Enter the dividend: ");
    gets(inbuf);
    valid_input = sscanf(inbuf, "%d", &dividend);
  }
  valid_input = 0;
  while (valid_input < 1) {
    printf("Enter the divisor: ");
    gets(inbuf);
    valid_input = sscanf(inbuf, "%d", &divisor);
    if (divisor == 0) {
      printf("Division by zero is not allowed\n");
      valid_input = 0;
    }
  }
  quotient = dividend / divisor;
  remainder = dividend % divisor;
  printf("%d / %d = %d and %d/%d\n", dividend, divisor, quotient, remainder,
         divisor);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    118c <main+0x5c>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <gets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
jmp    1149 <main+0x19>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11f5 <main+0xc5>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <gets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11f0 <main+0xc0>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
jmp    1193 <main+0x63>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x8(%rbp),%r9d
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa0,%rsp
lea    0xea9(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xeb2(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
jle    1170 <main+0x30>
lea    0xe7d(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe6e(%rip),%r15
lea    0x8(%rsp),%r12
lea    0xe91(%rip),%r13
jmp    11c4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
jg     11f7 <main+0xb7>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmpl   $0x0,0x8(%rsp)
jne    11c0 <main+0x80>
mov    %r13,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11c0 <main+0x80>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%r9d
mov    %esi,%eax
cltd
idiv   %r9d
mov    %edx,%r8d
lea    0xe1c(%rip),%rdi
mov    %r9d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter the dividend: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter the divisor: \00"
@.str.3 = [33 x i8] c"Division by zero is not allowed\0A\00"
@.str.4 = [24 x i8] c"%d / %d = %d and %d/%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [133 x i8]
store i32 0, i32* %1
store i32 0, i32* %6
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%14 = call i32 @gets(i8* %13)
%15 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 %16, i32* %6
br label %8
17: ; preds = %8
store i32 0, i32* %6
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%24 = call i32 @gets(i8* %23)
%25 = getelementptr inbounds [133 x i8], [133 x i8]* %7, i64 0, i64 0
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 %26, i32* %6
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %31
31: ; preds = %29, %21
br label %18
32: ; preds = %18
%33 = load i32, i32* %3
%34 = load i32, i32* %2
%35 = sdiv i32 %33, %34
store i32 %35, i32* %4
%36 = load i32, i32* %3
%37 = load i32, i32* %2
%38 = srem i32 %36, %37
store i32 %38, i32* %5
%39 = load i32, i32* %3
%40 = load i32, i32* %2
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = load i32, i32* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40, i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter the dividend: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter the divisor: \00"
@.str.4 = [24 x i8] c"%d / %d = %d and %d/%d\0A\00"
@str = [32 x i8] c"Division by zero is not allowed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [133 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [133 x i8], [133 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %0, %7
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @gets(i8* %6)
%10 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = icmp slt i32 %10, 1
br i1 %11, label %7, label %12
12: ; preds = %7, %20
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @gets(i8* %6)
%15 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = phi i32 [ 0, %18 ], [ %15, %12 ]
%22 = icmp slt i32 %21, 1
br i1 %22, label %12, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = load i32, i32* %1
%26 = sdiv i32 %24, %25
%27 = srem i32 %24, %25
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %25, i32 %26, i32 %27, i32 %25)
ret i32 0
}