#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 abs(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int dividend, divisor;
  int dividend_u, divisor_u;
  int hi, counter, quotient, remainder;
  unsigned int lo;
  dividend = atoi(argv[1]);
  divisor = atoi(argv[2]);
  if (divisor == 0) {
    fprintf(stderr, "try to divide by 0\n");
    exit(-1);
  }
  dividend_u = abs(dividend);
  divisor_u = abs(divisor);
  hi = 0;
  lo = dividend_u;
  counter = 32;
  hi = ((lo & 0x80000000) >> 31);
  lo <<= 1;
  while (counter > 0) {
    hi -= divisor_u;
    if (hi < 0) {
      hi += divisor_u;
      hi <<= 1;
      hi |= ((lo & 0x80000000) >> 31);
      lo <<= 1;
    } else {
      hi <<= 1;
      hi |= ((lo & 0x80000000) >> 31);
      lo <<= 1;
      lo |= 1;
    }
    counter--;
  }
  hi >>= 1;
  remainder = hi;
  quotient = lo;
  if (dividend < 0) {
    remainder *= -1;
  }
  if ((dividend & 0x80000000) != (divisor & 0x80000000)) {
    quotient *= -1;
  }
  fprintf(stdout, "0x%08x = 0x%08x * 0x%08x + 0x%08x\n", dividend, quotient,
          divisor, remainder);
  fprintf(stdout, "%d = %d * %d + %d\n", dividend, quotient, divisor,
          remainder);
  while (!getchar())
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11b1 <main+0x61>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x20,-0x28(%rbp)
mov    -0x34(%rbp),%eax
and    $0x80000000,%eax
shr    $0x1f,%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    127c <main+0x12c>
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1242 <main+0xf2>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
and    $0x80000000,%eax
shr    $0x1f,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126e <main+0x11e>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
and    $0x80000000,%eax
shr    $0x1f,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11f2 <main+0xa2>
mov    -0x24(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a2 <main+0x152>
imul   $0xffffffff,-0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
and    $0x80000000,%eax
mov    -0x18(%rbp),%ecx
and    $0x80000000,%ecx
cmp    %ecx,%eax
je     12c2 <main+0x172>
imul   $0xffffffff,-0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1328 <main+0x1d8>
jmp    132d <main+0x1dd>
jmp    130c <main+0x1bc>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
je     1226 <main+0xe6>
mov    %eax,%r15d
mov    %r14d,%eax
neg    %eax
cmovs  %r14d,%eax
mov    %r15d,%ecx
neg    %ecx
cmovs  %r15d,%ecx
add    %eax,%eax
xor    %edx,%edx
mov    $0x21,%esi
jmp    11a3 <main+0x63>
nopl   0x0(%rax,%rax,1)
shld   $0x1,%eax,%edi
add    %eax,%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0xffffffff,%esi
cmp    $0x1,%esi
jbe    11b1 <main+0x71>
mov    %edx,%edi
sub    %ecx,%edi
jns    1190 <main+0x50>
shld   $0x1,%eax,%edx
add    %eax,%eax
jmp    119b <main+0x5b>
sar    %edx
mov    %edx,%ebx
neg    %ebx
test   %r14d,%r14d
cmovns %edx,%ebx
mov    %eax,%ebp
neg    %ebp
mov    %r15d,%ecx
xor    %r14d,%ecx
cmovns %eax,%ebp
mov    0x2e07(%rip),%r12
mov    (%r12),%edi
lea    0xe38(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
lea    0xe3e(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
test   %eax,%eax
je     1210 <main+0xd0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"try to divide by 0\0A\00"
@stdout = global i32 0
@.str.1 = [35 x i8] c"0x%08x = 0x%08x * 0x%08x + 0x%08x\0A\00"
@.str.2 = [19 x i8] c"%d = %d * %d + %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %2
%30 = load i32, i32* %6
%31 = call i32 @abs(i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %7
%33 = call i32 @abs(i32 %32)
store i32 %33, i32* %9
store i32 0, i32* %10
%34 = load i32, i32* %8
store i32 %34, i32* %14
store i32 32, i32* %11
%35 = load i32, i32* %14
%36 = and i32 %35, -2147483648
%37 = lshr i32 %36, 31
store i32 %37, i32* %10
%38 = load i32, i32* %14
%39 = shl i32 %38, 1
store i32 %39, i32* %14
br label %40
40: ; preds = %74, %29
%41 = load i32, i32* %11
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %77
43: ; preds = %40
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = sub nsw i32 %45, %44
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %43
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = add nsw i32 %51, %50
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = shl i32 %53, 1
store i32 %54, i32* %10
%55 = load i32, i32* %14
%56 = and i32 %55, -2147483648
%57 = lshr i32 %56, 31
%58 = load i32, i32* %10
%59 = or i32 %58, %57
store i32 %59, i32* %10
%60 = load i32, i32* %14
%61 = shl i32 %60, 1
store i32 %61, i32* %14
br label %74
62: ; preds = %43
%63 = load i32, i32* %10
%64 = shl i32 %63, 1
store i32 %64, i32* %10
%65 = load i32, i32* %14
%66 = and i32 %65, -2147483648
%67 = lshr i32 %66, 31
%68 = load i32, i32* %10
%69 = or i32 %68, %67
store i32 %69, i32* %10
%70 = load i32, i32* %14
%71 = shl i32 %70, 1
store i32 %71, i32* %14
%72 = load i32, i32* %14
%73 = or i32 %72, 1
store i32 %73, i32* %14
br label %74
74: ; preds = %62, %49
%75 = load i32, i32* %11
%76 = add nsw i32 %75, -1
store i32 %76, i32* %11
br label %40
77: ; preds = %40
%78 = load i32, i32* %10
%79 = ashr i32 %78, 1
store i32 %79, i32* %10
%80 = load i32, i32* %10
store i32 %80, i32* %13
%81 = load i32, i32* %14
store i32 %81, i32* %12
%82 = load i32, i32* %6
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = load i32, i32* %13
%86 = mul nsw i32 %85, -1
store i32 %86, i32* %13
br label %87
87: ; preds = %84, %77
%88 = load i32, i32* %6
%89 = and i32 %88, -2147483648
%90 = load i32, i32* %7
%91 = and i32 %90, -2147483648
%92 = icmp ne i32 %89, %91
br i1 %92, label %93, label %96
93: ; preds = %87
%94 = load i32, i32* %12
%95 = mul nsw i32 %94, -1
store i32 %95, i32* %12
br label %96
96: ; preds = %93, %87
%97 = load i32, i32* @stdout
%98 = load i32, i32* %6
%99 = load i32, i32* %12
%100 = load i32, i32* %7
%101 = load i32, i32* %13
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %98, i32 %99, i32 %100, i32 %101)
%103 = load i32, i32* @stdout
%104 = load i32, i32* %6
%105 = load i32, i32* %12
%106 = load i32, i32* %7
%107 = load i32, i32* %13
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %104, i32 %105, i32 %106, i32 %107)
br label %109
109: ; preds = %113, %96
%110 = call i32 (...) @getchar()
%111 = icmp ne i32 %110, 0
%112 = xor i1 %111, true
br i1 %112, label %113, label %114
113: ; preds = %109
br label %109
114: ; preds = %109
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"try to divide by 0\0A\00"
@stdout = global i32 0
@.str.1 = [35 x i8] c"0x%08x = 0x%08x * 0x%08x + 0x%08x\0A\00"
@.str.2 = [19 x i8] c"%d = %d * %d + %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
%16 = tail call i32 @llvm.abs.i32(i32 %8, i1 true)
%17 = shl nuw i32 %15, 1
br label %18
18: ; preds = %14, %31
%19 = phi i32 [ %17, %14 ], [ %33, %31 ]
%20 = phi i32 [ 32, %14 ], [ %34, %31 ]
%21 = phi i32 [ 0, %14 ], [ %32, %31 ]
%22 = sub nsw i32 %21, %16
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = tail call i32 @llvm.fshl.i32(i32 %21, i32 %19, i32 1)
%26 = shl i32 %19, 1
br label %31
27: ; preds = %18
%28 = tail call i32 @llvm.fshl.i32(i32 %22, i32 %19, i32 1)
%29 = shl i32 %19, 1
%30 = or i32 %29, 1
br label %31
31: ; preds = %27, %24
%32 = phi i32 [ %25, %24 ], [ %28, %27 ]
%33 = phi i32 [ %26, %24 ], [ %30, %27 ]
%34 = add nsw i32 %20, -1
%35 = icmp ugt i32 %20, 1
br i1 %35, label %18, label %36
36: ; preds = %31
%37 = ashr i32 %32, 1
%38 = icmp slt i32 %5, 0
%39 = sub nsw i32 0, %37
%40 = select i1 %38, i32 %39, i32 %37
%41 = xor i32 %8, %5
%42 = icmp sgt i32 %41, -1
%43 = sub nsw i32 0, %33
%44 = select i1 %42, i32 %33, i32 %43
%45 = load i32, i32* @stdout
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %44, i32 %8, i32 %40)
%47 = load i32, i32* @stdout
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %44, i32 %8, i32 %40)
br label %49
49: ; preds = %49, %36
%50 = tail call i32 (...) @getchar()
%51 = icmp eq i32 %50, 0
br i1 %51, label %49, label %52
52: ; preds = %49
ret i32 0
}