#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 */
struct Molecule_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int get_nElectron(struct Molecule_t *);
int /*<<< orphan*/ printf(char *);
int get_nEB(struct Molecule_t *mol, int M) {
  int N;
  N = get_nElectron(mol);
  if ((N - M + 1) % 2 == 1) {
    printf("get_nEB - error number of electron does not match multiplicity\n");
    exit(-1);
  }
  if ((N - M + 1) < 0) {
    printf(
        "get_nEB - error multiplicity cannot larger than number of electron\n");
    exit(-1);
  }
  return (N - M + 1) / 2;
}


x86 assembly (clang, -O0):
<get_nEB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_nElectron@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    117b <get_nEB+0x4b>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
cmp    $0x0,%eax
jge    11a3 <get_nEB+0x73>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nEB>:
push   %rbx
mov    %esi,%ebx
call   1040 <get_nElectron@plt>
mov    %eax,%ecx
sub    %ebx,%ecx
lea    0x1(%rcx),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %ecx,%edx
add    $0x1,%edx
and    $0xfffffffe,%edx
neg    %edx
add    %ecx,%edx
add    $0x1,%edx
cmp    $0x1,%edx
je     1161 <get_nEB+0x31>
cmp    $0xfffffffe,%ecx
jle    116a <get_nEB+0x3a>
shr    %eax
pop    %rbx
ret
lea    0xedb(%rip),%rdi
jmp    1171 <get_nEB+0x41>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.Molecule_t = type { i32 }
@.str = [64 x i8] c"get_nEB - error number of electron does not match multiplicity\0A\00"
@.str.1 = [68 x i8] c"get_nEB - error multiplicity cannot larger than number of electron\0A\00"
define i32 @get_nEB(%struct.Molecule_t* %0, i32 %1) {
%3 = alloca %struct.Molecule_t*
%4 = alloca i32
%5 = alloca i32
store %struct.Molecule_t* %0, %struct.Molecule_t** %3
store i32 %1, i32* %4
%6 = load %struct.Molecule_t*, %struct.Molecule_t** %3
%7 = call i32 @get_nElectron(%struct.Molecule_t* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %8, %9
%11 = add nsw i32 %10, 1
%12 = srem i32 %11, 2
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %17
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = sub nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = sdiv i32 %30, 2
ret i32 %31
}

LLVM IR (-O2):
%struct.Molecule_t = type { i32 }
@str = [67 x i8] c"get_nEB - error multiplicity cannot larger than number of electron\00"
@str.2 = [63 x i8] c"get_nEB - error number of electron does not match multiplicity\00"
define i32 @get_nEB(%struct.Molecule_t* %0, i32 %1) {
%3 = tail call i32 @get_nElectron(%struct.Molecule_t* %0)
%4 = sub nsw i32 %3, %1
%5 = add nsw i32 %4, 1
%6 = srem i32 %5, 2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = icmp slt i32 %4, -1
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %11
%17 = lshr i32 %5, 1
ret i32 %17
}