int direct_addressing(base, counter) {
  int address_bits = 0b0000000011111111;
  int negative = 0b0000000100000000;
  int number = address_bits & base;
  int n_check = negative & base;
  if (n_check == 0b0000000100000000) {
    number = number - 0b100000000;
    number = number + (counter + 3000 - 50);
    printf("%d\n", number);
  } else {
    number = number + (counter + 3000 - 50);
    printf("%d\n", number);
  }
  return 0;
}


x86 assembly (clang, -O0):
<direct_addressing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xff,-0xc(%rbp)
movl   $0x100,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jne    1180 <direct_addressing+0x70>
mov    -0x14(%rbp),%eax
sub    $0x100,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0xbb8,%ecx
sub    $0x32,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a5 <direct_addressing+0x95>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0xbb8,%ecx
sub    $0x32,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<direct_addressing>:
push   %rax
movzbl %dil,%eax
mov    %edi,%ecx
shl    $0x17,%ecx
sar    $0x1f,%ecx
and    $0xffffff00,%ecx
or     %eax,%ecx
add    %ecx,%esi
add    $0xb86,%esi
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @direct_addressing(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 255, i32* %5
store i32 256, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = and i32 %9, %10
store i32 %11, i32* %7
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = and i32 %12, %13
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 256
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 256
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 3000
%23 = sub nsw i32 %22, 50
%24 = add nsw i32 %20, %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %35
27: ; preds = %2
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 3000
%31 = sub nsw i32 %30, 50
%32 = add nsw i32 %28, %31
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27, %17
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @direct_addressing(i32 %0, i32 %1) {
%3 = and i32 %0, 256
%4 = icmp eq i32 %3, 0
%5 = and i32 %0, 255
%6 = select i1 %4, i32 0, i32 -256
%7 = or i32 %5, %6
%8 = add nsw i32 %1, 2950
%9 = add nsw i32 %8, %7
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
ret i32 0
}