#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 */
typedef int size;
typedef int head;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 4) {
    char *name;
    if (argc)
      name = argv[0];
    else
      name = "circ_calc";
    fprintf(stderr, "usage: %s head tail size\n", name);
    return 1;
  }
  int head, tail, size;
  if (sscanf(argv[1], "%d", &head) != 1)
    return -1;
  if (sscanf(argv[2], "%d", &tail) != 1)
    return -2;
  if (sscanf(argv[3], "%d", &size) != 1)
    return -3;
  printf("CIRC_CNT(%d,%d,%d) == %d\n", head, tail, size,
         (((head) - (tail)) & ((size)-1)));
  printf("CIRC_SPACE(%d,%d,%d) == %d\n", head, tail, size,
         ((((tail)) - (((head) + 1))) & (((size)) - 1)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     119a <main+0x6a>
cmpl   $0x0,-0x8(%rbp)
je     116a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <main+0x45>
lea    0xe8f(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1279 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11c7 <main+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    1279 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4e(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11f4 <main+0xc4>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1279 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe21(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1221 <main+0xf1>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1279 <main+0x149>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
sub    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
and    %eax,%r8d
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
sub    %eax,%r8d
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
and    %eax,%r8d
lea    0xdd4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1200 <main+0xd0>
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1209 <main+0xd9>
mov    0x8(%rbx),%rdi
lea    0xed0(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    1226 <main+0xf6>
mov    0x10(%rbx),%rdi
lea    0xeab(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x1,%ecx
jne    1226 <main+0xf6>
mov    0x18(%rbx),%rdi
lea    0xe86(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0xfffffffd,%eax
cmp    $0x1,%ecx
jne    1226 <main+0xf6>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %esi,%eax
sub    %edx,%eax
lea    -0x1(%rcx),%r8d
and    %eax,%r8d
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %esi,%eax
not    %eax
add    %edx,%eax
lea    -0x1(%rcx),%r8d
and    %eax,%r8d
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1226 <main+0xf6>
lea    0xdf9(%rip),%rdx
jmp    120c <main+0xdc>
mov    (%rbx),%rdx
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"circ_calc\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"usage: %s head tail size\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"CIRC_CNT(%d,%d,%d) == %d\0A\00"
@.str.4 = [28 x i8] c"CIRC_SPACE(%d,%d,%d) == %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%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 %24
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %20
19: ; preds = %12
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
br label %20
20: ; preds = %19, %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %6
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %67
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -1, i32* %3
br label %67
31: ; preds = %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -2, i32* %3
br label %67
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 -3, i32* %3
br label %67
45: ; preds = %38
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = sub nsw i32 %49, %50
%52 = load i32, i32* %9
%53 = sub nsw i32 %52, 1
%54 = and i32 %51, %53
%55 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47, i32 %48, i32 %54)
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = load i32, i32* %8
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
%62 = sub nsw i32 %59, %61
%63 = load i32, i32* %9
%64 = sub nsw i32 %63, 1
%65 = and i32 %62, %64
%66 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %57, i32 %58, i32 %65)
store i32 0, i32* %3
br label %67
67: ; preds = %45, %44, %37, %30, %20
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [10 x i8] c"circ_calc\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"usage: %s head tail size\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"CIRC_CNT(%d,%d,%d) == %d\0A\00"
@.str.4 = [28 x i8] c"CIRC_SPACE(%d,%d,%d) == %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
switch i32 %0, label %6 [
i32 4, label %12
i32 0, label %8
]
6: ; preds = %2
%7 = load i8*, i8** %1
br label %8
8: ; preds = %2, %6
%9 = phi i8* [ %7, %6 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %48
12: ; preds = %2
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %46
20: ; preds = %12
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = sub nsw i32 %31, %32
%35 = add nsw i32 %33, -1
%36 = and i32 %35, %34
%37 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %36)
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = xor i32 %38, -1
%42 = add i32 %39, %41
%43 = add nsw i32 %40, -1
%44 = and i32 %43, %42
%45 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %44)
br label %46
46: ; preds = %25, %20, %12, %30
%47 = phi i32 [ 0, %30 ], [ -1, %12 ], [ -2, %20 ], [ -3, %25 ]
br label %48
48: ; preds = %46, %8
%49 = phi i32 [ 1, %8 ], [ %47, %46 ]
ret i32 %49
}