#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 /*<<< orphan*/ scanf(char *, int *);
void main() {
  int val, a, b;
  scanf("%d", &val);
  a = val >> (sizeof(int) * 8 - 1);
  printf("%d\n", a);
  if (a == 0) {
    printf("val = %o %d", val, a);
  } else if (a == -1) {
    a = a << (sizeof(int) * 8 - 1);
    b = a | (~val);
    printf("val = %o %d", b + 1, b + 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xede(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1175 <main+0x55>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b5 <main+0x95>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b0 <main+0x90>
mov    -0x8(%rbp),%eax
shl    $0x1f,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
xor    $0xffffffff,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b5 <main+0x95>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%esi
sar    $0x1f,%esi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
test   %ebx,%ebx
js     1160 <main+0x40>
lea    0xea8(%rip),%rdi
xor    %edx,%edx
jmp    1174 <main+0x54>
not    %esi
or     $0x80000000,%esi
add    $0x1,%esi
lea    0xe92(%rip),%rdi
mov    %esi,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [12 x i8] c"val = %o %d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = ashr i32 %5, 31
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
br label %31
15: ; preds = %0
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %2
%20 = shl i32 %19, 31
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = load i32, i32* %1
%23 = xor i32 %22, -1
%24 = or i32 %21, %23
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %28)
br label %30
30: ; preds = %18, %15
br label %31
31: ; preds = %30, %11
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [12 x i8] c"val = %o %d\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = ashr i32 %4, 31
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %4, -1
%8 = load i32, i32* %1
br i1 %7, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 0)
br label %16
11: ; preds = %0
%12 = xor i32 %8, -1
%13 = or i32 %12, -2147483648
%14 = add nsw i32 %13, 1
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %14)
br label %16
16: ; preds = %11, %9
ret void
}