#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__ isdigit(char);
scalar_t__ ispunct(char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void find_driver_info(char *ifname, char *driver, char *version, char *firmware,
                      char *bus, int len) {
  int i;
  strncpy(driver, ifname, len);
  driver[len - 1] = 0;
  for (i = strlen(driver) - 1;
       ((isdigit(driver[i])) || (ispunct(driver[i]))) && (i >= 0); i--) {
    driver[i] = 0;
  }
  if (strlen(driver) == 0)
    strncpy(driver, "NoAlpha", len);
  strncpy(version, "Unavailable", len);
  strncpy(firmware, "Unavailable", len);
  strncpy(bus, "Unavailable", len);
  version[len - 1] = 0;
  firmware[len - 1] = 0;
  bus[len - 1] = 0;
  return;
}


x86 assembly (clang, -O0):
<find_driver_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
jne    11ce <find_driver_info+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <ispunct@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
je     11d8 <find_driver_info+0x98>
cmpl   $0x0,-0x30(%rbp)
setge  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11e8 <find_driver_info+0xa8>
jmp    1202 <find_driver_info+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    1190 <find_driver_info+0x50>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1227 <find_driver_info+0xe7>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdde(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdd3(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdc0(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdad(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_driver_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebp
mov    %r8,(%rsp)
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rbx,%rdi
mov    %r9d,%edx
call   1030 <strncpy@plt>
movslq %ebp,%r13
movb   $0x0,-0x1(%r13,%rbx,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%r14
nopl   (%rax)
movsbl -0x1(%rbx,%r14,1),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    11a0 <find_driver_info+0x60>
movsbl -0x1(%rbx,%r14,1),%edi
call   1060 <ispunct@plt>
test   %rax,%rax
je     11b1 <find_driver_info+0x71>
test   %r14,%r14
jle    11b1 <find_driver_info+0x71>
movb   $0x0,-0x1(%rbx,%r14,1)
add    $0xffffffffffffffff,%r14
jmp    1180 <find_driver_info+0x40>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jne    11ce <find_driver_info+0x8e>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
lea    0xe33(%rip),%r14
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r12,%r13,1)
movb   $0x0,-0x1(%r15,%r13,1)
movb   $0x0,-0x1(%rbx,%r13,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"NoAlpha\00"
@.str.1 = [12 x i8] c"Unavailable\00"
define void @find_driver_info(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %8
%15 = load i8*, i8** %7
%16 = load i32, i32* %12
%17 = call i32 @strncpy(i8* %14, i8* %15, i32 %16)
%18 = load i8*, i8** %8
%19 = load i32, i32* %12
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %13
br label %26
26: ; preds = %52, %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %42, label %34
34: ; preds = %26
%35 = load i8*, i8** %8
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i64 @ispunct(i8 signext %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %34, %26
%43 = load i32, i32* %13
%44 = icmp sge i32 %43, 0
br label %45
45: ; preds = %42, %34
%46 = phi i1 [ false, %34 ], [ %44, %42 ]
br i1 %46, label %47, label %55
47: ; preds = %45
%48 = load i8*, i8** %8
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %47
%53 = load i32, i32* %13
%54 = add nsw i32 %53, -1
store i32 %54, i32* %13
br label %26
55: ; preds = %45
%56 = load i8*, i8** %8
%57 = call i32 @strlen(i8* %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i8*, i8** %8
%61 = load i32, i32* %12
%62 = call i32 @strncpy(i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %59, %55
%64 = load i8*, i8** %9
%65 = load i32, i32* %12
%66 = call i32 @strncpy(i8* %64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %65)
%67 = load i8*, i8** %10
%68 = load i32, i32* %12
%69 = call i32 @strncpy(i8* %67, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %68)
%70 = load i8*, i8** %11
%71 = load i32, i32* %12
%72 = call i32 @strncpy(i8* %70, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = load i8*, i8** %9
%74 = load i32, i32* %12
%75 = sub nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
store i8 0, i8* %77
%78 = load i8*, i8** %10
%79 = load i32, i32* %12
%80 = sub nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %78, i64 %81
store i8 0, i8* %82
%83 = load i8*, i8** %11
%84 = load i32, i32* %12
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %83, i64 %86
store i8 0, i8* %87
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"NoAlpha\00"
@.str.1 = [12 x i8] c"Unavailable\00"
define void @find_driver_info(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %5)
%8 = add nsw i32 %5, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %28, %6
%14 = phi i64 [ %15, %28 ], [ %12, %6 ]
%15 = add nsw i64 %14, -1
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i8, i8* %16
%22 = tail call i64 @ispunct(i8 signext %21)
%23 = icmp ne i64 %22, 0
%24 = icmp sgt i64 %14, 0
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %28, label %29
26: ; preds = %13
%27 = icmp sgt i64 %14, 0
br i1 %27, label %28, label %29
28: ; preds = %20, %26
store i8 0, i8* %16
br label %13
29: ; preds = %20, %26
%30 = tail call i32 @strlen(i8* %1)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %34
34: ; preds = %32, %29
%35 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%36 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%37 = tail call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%38 = getelementptr inbounds i8, i8* %2, i64 %9
store i8 0, i8* %38
%39 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 0, i8* %39
%40 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 0, i8* %40
ret void
}