#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 */
short abs(short);
int _abs2(int src1) {
  short s1[2], r[2];
  int result;
  *((int *)s1) = src1;
  if ((unsigned short)s1[1] == (unsigned short)0x8000)
    r[1] = 0x7fff;
  else
    r[1] = abs(s1[1]);
  if ((unsigned short)s1[0] == (unsigned short)0x8000)
    r[0] = 0x7fff;
  else
    r[0] = abs(s1[0]);
  result = *(int *)r;
  return result;
}


x86 assembly (clang, -O0):
<_abs2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movzwl -0x6(%rbp),%eax
cmp    $0x8000,%eax
jne    113b <_abs2+0x2b>
movw   $0x7fff,-0xa(%rbp)
jmp    1148 <_abs2+0x38>
movswl -0x6(%rbp),%edi
call   1030 <abs@plt>
mov    %ax,-0xa(%rbp)
movzwl -0x8(%rbp),%eax
cmp    $0x8000,%eax
jne    1162 <_abs2+0x52>
movw   $0x7fff,-0xc(%rbp)
jmp    116f <_abs2+0x5f>
movswl -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %ax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_abs2>:
movzwl %di,%eax
shr    $0x10,%edi
mov    %edi,%ecx
neg    %cx
cmovs  %di,%cx
shl    $0x10,%ecx
cmp    $0x8000,%edi
mov    $0x7fff0000,%edx
cmovne %ecx,%edx
mov    %eax,%ecx
neg    %cx
cmovs  %ax,%cx
cmp    $0x8000,%eax
movzwl %cx,%ecx
mov    $0x7fff,%eax
cmovne %ecx,%eax
or     %edx,%eax
ret

LLVM IR (-O0):
define i32 @_abs2(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i16]
%4 = alloca [2 x i16]
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
%8 = bitcast i16* %7 to i32*
store i32 %6, i32* %8
%9 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 1
%10 = load i16, i16* %9
%11 = zext i16 %10 to i32
%12 = icmp eq i32 %11, 32768
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = getelementptr inbounds [2 x i16], [2 x i16]* %4, i64 0, i64 1
store i16 32767, i16* %14
br label %20
15: ; preds = %1
%16 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 1
%17 = load i16, i16* %16
%18 = call signext i16 @abs(i16 signext %17)
%19 = getelementptr inbounds [2 x i16], [2 x i16]* %4, i64 0, i64 1
store i16 %18, i16* %19
br label %20
20: ; preds = %15, %13
%21 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
%22 = load i16, i16* %21
%23 = zext i16 %22 to i32
%24 = icmp eq i32 %23, 32768
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = getelementptr inbounds [2 x i16], [2 x i16]* %4, i64 0, i64 0
store i16 32767, i16* %26
br label %32
27: ; preds = %20
%28 = getelementptr inbounds [2 x i16], [2 x i16]* %3, i64 0, i64 0
%29 = load i16, i16* %28
%30 = call signext i16 @abs(i16 signext %29)
%31 = getelementptr inbounds [2 x i16], [2 x i16]* %4, i64 0, i64 0
store i16 %30, i16* %31
br label %32
32: ; preds = %27, %25
%33 = getelementptr inbounds [2 x i16], [2 x i16]* %4, i64 0, i64 0
%34 = bitcast i16* %33 to i32*
%35 = load i32, i32* %34
store i32 %35, i32* %5
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @_abs2(i32 %0) {
%2 = trunc i32 %0 to i16
%3 = lshr i32 %0, 16
%4 = icmp eq i32 %3, 32768
%5 = trunc i32 %3 to i16
%6 = tail call i16 @llvm.abs.i16(i16 %5, i1 true)
%7 = zext i16 %6 to i32
%8 = shl nuw nsw i32 %7, 16
%9 = select i1 %4, i32 2147418112, i32 %8
%10 = and i32 %0, 65535
%11 = icmp eq i32 %10, 32768
%12 = tail call i16 @llvm.abs.i16(i16 %2, i1 true)
%13 = zext i16 %12 to i32
%14 = select i1 %11, i32 32767, i32 %13
%15 = or i32 %9, %14
ret i32 %15
}