#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*/ printf(char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
main(int argc, char *argv[]) {
  int n;
  sscanf(argv[1], "%i", &n);
  if (!strncmp(argv[1], "0x", 2) && strlen(argv[1]) == 6 && (n & 0x8000L))
    n |= 0xFFFF0000L;
  printf("0x%08X => %d\n", n, n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe86(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ce <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
jne    11ce <main+0x8e>
movslq -0x14(%rbp),%rax
and    $0x8000,%rax
cmp    $0x0,%rax
je     11ce <main+0x8e>
movslq -0x14(%rbp),%rax
movabs $0xffff0000,%rcx
or     %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xead(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
mov    0x8(%rbx),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1198 <main+0x58>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
jne    1198 <main+0x58>
mov    0xc(%rsp),%eax
test   $0x8000,%eax
je     1198 <main+0x58>
or     $0xffff0000,%eax
mov    %eax,0xc(%rsp)
mov    0xc(%rsp),%edx
lea    0xe63(%rip),%rdi
mov    %edx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"0x\00"
@.str.2 = [14 x i8] c"0x%08X => %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%15 = icmp ne i32 %14, 0
br i1 %15, label %32, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = icmp eq i32 %20, 6
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = and i64 %24, 32768
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = or i64 %29, 4294901760
%31 = trunc i64 %30 to i32
store i32 %31, i32* %6
br label %32
32: ; preds = %27, %22, %16, %2
%33 = load i32, i32* %6
%34 = load i32, i32* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"0x\00"
@.str.2 = [14 x i8] c"0x%08X => %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i8*, i8** %5
%9 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp eq i32 %13, 6
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* %3
%17 = and i32 %16, 32768
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = or i32 %16, -65536
store i32 %20, i32* %3
br label %21
21: ; preds = %19, %15, %11, %2
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %22)
ret i32 0
}