int GROTER(cdev, ldev, w_cdev, w_ldev)
char *cdev;
long int *ldev;
int w_cdev, w_ldev;
{
  int fd, n;
  char name[64];
  n = *ldev;
  if (n > 63)
    n = 63;
  strncpy(name, cdev, n);
  name[n] = '\0';
  if ((fd = open(name, 2)) == -1) {
    perror(name);
    return -1;
  } else {
    return fd;
  }
}


x86 assembly (clang, -O0):
<GROTER>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x28(%rbp)
cmpl   $0x3f,-0x28(%rbp)
jle    1161 <GROTER+0x31>
movl   $0x3f,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
movslq -0x28(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11ae <GROTER+0x7e>
lea    -0x70(%rbp),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <GROTER+0x84>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GROTER>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rax
mov    (%rsi),%rcx
cmp    $0x3f,%ecx
movslq %ecx,%rcx
mov    $0x3f,%ebx
cmovl  %rcx,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1181 <GROTER+0x51>
mov    %rsp,%rdi
xor    %eax,%eax
call   1050 <perror@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @GROTER(i8* %0, i64* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [64 x i8]
store i8* %0, i8** %6
store i64* %1, i64** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i64*, i64** %7
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp sgt i32 %16, 63
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 63, i32* %11
br label %19
19: ; preds = %18, %4
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = call i8* @strncpy(i8* %20, i8* %21, i64 %23)
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%29 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %28, i32 2)
store i32 %29, i32* %10
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%33 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %32)
store i32 -1, i32* %5
br label %36
34: ; preds = %19
%35 = load i32, i32* %10
store i32 %35, i32* %5
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
define i32 @GROTER(i8* nocapture %0, i64* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = load i64, i64* %1
%8 = trunc i64 %7 to i32
%9 = icmp slt i32 %8, 63
%10 = shl i64 %7, 32
%11 = ashr exact i64 %10, 32
%12 = select i1 %9, i64 %11, i64 63
%13 = call i8* @strncpy(i8* %6, i8* %0, i64 %12)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %12
store i8 0, i8* %14
%15 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %6, i32 2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %6)
br label %19
19: ; preds = %4, %17
ret i32 %15
}