#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*/ snprintf(char *, int, char *, char const *const, int, int,
                            ...);
const char *syscall_str(int msb, int start, int end) {
  static char buf[64];
  const char *const type = (start & 0x40000000) ? "x32" : "x64";
  int lsb = start;
  if (lsb < 0)
    lsb |= 0x40000000;
  else
    lsb &= ~0x40000000;
  if (start == end)
    snprintf(buf, sizeof buf, "%s syscall %d:%d", type, msb, lsb);
  else
    snprintf(buf, sizeof buf, "%s syscalls %d:%d..%d", type, msb, lsb,
             lsb + (end - start));
  return buf;
}


x86 assembly (clang, -O0):
<syscall_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edx
and    $0x40000000,%edx
lea    0xed3(%rip),%rax
lea    0xec8(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1163 <syscall_str+0x53>
mov    -0x1c(%rbp),%eax
or     $0x40000000,%eax
mov    %eax,-0x1c(%rbp)
jmp    116e <syscall_str+0x5e>
mov    -0x1c(%rbp),%eax
and    $0xbfffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11a5 <syscall_str+0x95>
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0x2eb3(%rip),%rdi
mov    $0x40,%esi
lea    0xe6f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d9 <syscall_str+0xc9>
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%edx
sub    -0x8(%rbp),%edx
add    %edx,%eax
lea    0x2e7d(%rip),%rdi
mov    $0x40,%esi
lea    0xe4a(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e60(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<syscall_str>:
push   %rax
mov    %edi,%r8d
test   $0x40000000,%esi
lea    0xee3(%rip),%rax
lea    0xed8(%rip),%rcx
cmove  %rax,%rcx
mov    %esi,%eax
and    $0xbfffffff,%eax
mov    %esi,%r9d
shr    %r9d
and    $0x40000000,%r9d
or     %eax,%r9d
sub    %esi,%edx
jne    1157 <syscall_str+0x47>
lea    0x2ef2(%rip),%rdi
lea    0xeb3(%rip),%rdx
jmp    116b <syscall_str+0x5b>
add    %r9d,%edx
mov    %edx,(%rsp)
lea    0x2edc(%rip),%rdi
lea    0xeae(%rip),%rdx
mov    $0x40,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2ec2(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@syscall_str.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"x32\00"
@.str.1 = [4 x i8] c"x64\00"
@.str.2 = [17 x i8] c"%s syscall %d:%d\00"
@.str.3 = [22 x i8] c"%s syscalls %d:%d..%d\00"
define i8* @syscall_str(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = and i32 %9, 1073741824
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
store i8* %13, i8** %7
%14 = load i32, i32* %5
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %8
%19 = or i32 %18, 1073741824
store i32 %19, i32* %8
br label %23
20: ; preds = %3
%21 = load i32, i32* %8
%22 = and i32 %21, -1073741825
store i32 %22, i32* %8
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i32, i32* %4
%30 = load i32, i32* %8
%31 = call i32 (i8*, i32, i8*, i8*, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %29, i32 %30)
br label %42
32: ; preds = %23
%33 = load i8*, i8** %7
%34 = load i32, i32* %4
%35 = load i32, i32* %8
%36 = load i32, i32* %8
%37 = load i32, i32* %6
%38 = load i32, i32* %5
%39 = sub nsw i32 %37, %38
%40 = add nsw i32 %36, %39
%41 = call i32 (i8*, i32, i8*, i8*, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32 %34, i32 %35, i32 %40)
br label %42
42: ; preds = %32, %27
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@syscall_str.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"x32\00"
@.str.1 = [4 x i8] c"x64\00"
@.str.2 = [17 x i8] c"%s syscall %d:%d\00"
@.str.3 = [22 x i8] c"%s syscalls %d:%d..%d\00"
define i8* @syscall_str(i32 %0, i32 %1, i32 %2) {
%4 = and i32 %1, 1073741824
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)
%7 = and i32 %1, -1073741825
%8 = lshr i32 %1, 1
%9 = and i32 %8, 1073741824
%10 = or i32 %9, %7
%11 = icmp eq i32 %2, %1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 (i8*, i32, i8*, i8*, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %0, i32 %10)
br label %18
14: ; preds = %3
%15 = sub i32 %2, %1
%16 = add nsw i32 %15, %10
%17 = tail call i32 (i8*, i32, i8*, i8*, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %0, i32 %10, i32 %16)
br label %18
18: ; preds = %14, %12
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @syscall_str.buf, i64 0, i64 0)
}