#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
unsigned int getbits(unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, unsigned int,
                          unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned int x, n, p, result;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <x> <position> <field-width>\n", argv[0]);
    return 1;
  } else {
    x = (unsigned int)atoi(argv[1]);
    p = (unsigned int)atoi(argv[2]);
    n = (unsigned int)atoi(argv[3]);
  }
  result = getbits(x, p, n);
  printf("x = %d 0x%X result: %d 0x%X\n", x, x, result, result);
  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)
cmpl   $0x4,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <getbits@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1196 <main+0x56>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %eax,%edx
call   1040 <getbits@plt>
lea    0xea6(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %eax,%ecx
mov    %eax,%r8d
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11b3 <main+0x73>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s <x> <position> <field-width>\0A\00"
@.str.1 = [29 x i8] c"x = %d 0x%X result: %d 0x%X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %44
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @atoi(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @atoi(i8* %26)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %8
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i64 @atoi(i8* %31)
%33 = trunc i64 %32 to i32
store i32 %33, i32* %7
br label %34
34: ; preds = %18
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = call i32 @getbits(i32 %35, i32 %36, i32 %37)
store i32 %38, i32* %9
%39 = load i32, i32* %6
%40 = load i32, i32* %6
%41 = load i32, i32* %9
%42 = load i32, i32* %9
%43 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %40, i32 %41, i32 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %34, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s <x> <position> <field-width>\0A\00"
@.str.1 = [29 x i8] c"x = %d 0x%X result: %d 0x%X\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @atoi(i8* %14)
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i64 @atoi(i8* %18)
%20 = trunc i64 %19 to i32
%21 = tail call i32 @getbits(i32 %12, i32 %16, i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %12, i32 %21, i32 %21)
br label %23
23: ; preds = %8, %4
%24 = phi i32 [ 1, %4 ], [ 0, %8 ]
ret i32 %24
}