#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 */
double atan2(int const, int const);
double hypot(int const, int const);
void rect_to_polar(const int a[2], const int b[2], double *r, double *th) {
  if (r)
    *r = hypot(b[0] - a[0], b[1] - a[1]);
  if (th)
    *th = atan2(b[0] - a[0], b[1] - a[1]);
}


x86 assembly (clang, -O0):
<rect_to_polar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116a <rect_to_polar+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
sub    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%rax
sub    0x4(%rax),%esi
call   1040 <hypot@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     119c <rect_to_polar+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
sub    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%rax
sub    0x4(%rax),%esi
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rect_to_polar>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
test   %rdx,%rdx
je     1150 <rect_to_polar+0x30>
mov    %rdx,%r12
mov    (%rbx),%edi
mov    0x4(%rbx),%esi
sub    (%r15),%edi
sub    0x4(%r15),%esi
call   1040 <hypot@plt>
movsd  %xmm0,(%r12)
test   %r14,%r14
je     116b <rect_to_polar+0x4b>
mov    (%rbx),%edi
mov    0x4(%rbx),%esi
sub    (%r15),%edi
sub    0x4(%r15),%esi
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @rect_to_polar(i32* %0, i32* %1, double* %2, double* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca double*
%8 = alloca double*
store i32* %0, i32** %5
store i32* %1, i32** %6
store double* %2, double** %7
store double* %3, double** %8
%9 = load double*, double** %7
%10 = icmp ne double* %9, null
br i1 %10, label %11, label %28
11: ; preds = %4
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %14, %17
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = sub nsw i32 %21, %24
%26 = call double @hypot(i32 %18, i32 %25)
%27 = load double*, double** %7
store double %26, double* %27
br label %28
28: ; preds = %11, %4
%29 = load double*, double** %8
%30 = icmp ne double* %29, null
br i1 %30, label %31, label %48
31: ; preds = %28
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 0
%34 = load i32, i32* %33
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = sub nsw i32 %34, %37
%39 = load i32*, i32** %6
%40 = getelementptr inbounds i32, i32* %39, i64 1
%41 = load i32, i32* %40
%42 = load i32*, i32** %5
%43 = getelementptr inbounds i32, i32* %42, i64 1
%44 = load i32, i32* %43
%45 = sub nsw i32 %41, %44
%46 = call double @atan2(i32 %38, i32 %45)
%47 = load double*, double** %8
store double %46, double* %47
br label %48
48: ; preds = %31, %28
ret void
}

LLVM IR (-O2):
define void @rect_to_polar(i32* nocapture %0, i32* nocapture %1, double* writeonly %2, double* writeonly %3) {
%5 = icmp eq double* %2, null
br i1 %5, label %16, label %6
6: ; preds = %4
%7 = load i32, i32* %1
%8 = load i32, i32* %0
%9 = sub nsw i32 %7, %8
%10 = getelementptr inbounds i32, i32* %1, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds i32, i32* %0, i64 1
%13 = load i32, i32* %12
%14 = sub nsw i32 %11, %13
%15 = tail call double @hypot(i32 %9, i32 %14)
store double %15, double* %2
br label %16
16: ; preds = %6, %4
%17 = icmp eq double* %3, null
br i1 %17, label %28, label %18
18: ; preds = %16
%19 = load i32, i32* %1
%20 = load i32, i32* %0
%21 = sub nsw i32 %19, %20
%22 = getelementptr inbounds i32, i32* %1, i64 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %0, i64 1
%25 = load i32, i32* %24
%26 = sub nsw i32 %23, %25
%27 = tail call double @atan2(i32 %21, i32 %26)
store double %27, double* %3
br label %28
28: ; preds = %18, %16
ret void
}