#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 */
unsigned int invert(unsigned int, int, int);
unsigned int invert2(unsigned int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  unsigned x = ~0;
  unsigned r;
  printf("x = %u\n", x);
  printf("Invert 16 bits from 32nd position on\n");
  r = invert(x, 31, 16);
  printf("%u\n", r);
  printf("Invert 16 bits from 16th position on\n");
  r = invert2(x, 15, 16);
  printf("%u\n", r);
  return 0;
}


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)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x1f,%esi
mov    $0x10,%edx
call   1030 <invert@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0xf,%esi
mov    $0x10,%edx
call   1050 <invert2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
mov    $0x1f,%esi
mov    $0x10,%edx
call   1030 <invert@plt>
lea    0xe89(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
mov    $0xf,%esi
mov    $0x10,%edx
call   1060 <invert2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"x = %u\0A\00"
@.str.1 = [38 x i8] c"Invert 16 bits from 32nd position on\0A\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [38 x i8] c"Invert 16 bits from 16th position on\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%8 = load i32, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %6
%12 = call i32 @invert(i32 %11, i32 31, i32 16)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = call i32 @invert2(i32 %16, i32 15, i32 16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"x = %u\0A\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@str = [37 x i8] c"Invert 16 bits from 32nd position on\00"
@str.4 = [37 x i8] c"Invert 16 bits from 16th position on\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 -1)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @invert(i32 -1, i32 31, i32 16)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i32 @invert2(i32 -1, i32 15, i32 16)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
ret i32 0
}