#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*/ free(char *);
char *match_dev(char *, int);
char *strchr(char *, char);
char *strndup(char *, int);
int strtol(char *, char **, int /*<<< orphan*/);
char *cc_usbdevs_find_by_arg(char *arg, char *default_product) {
  char *product;
  int serial;
  char *end;
  char *colon;
  char *tty;
  if (arg) {
    serial = strtol(arg, &end, 0);
    if (end != arg) {
      if (*end != '\0')
        return NULL;
      product = NULL;
    } else {
      colon = strchr(arg, ':');
      if (colon) {
        product = strndup(arg, colon - arg);
        serial = strtol(colon + 1, &end, 0);
        if (*end != '\0')
          return NULL;
      } else {
        product = arg;
        serial = 0;
      }
    }
  } else {
    product = NULL;
    serial = 0;
  }
  tty = NULL;
  if (!product && default_product)
    tty = match_dev(default_product, serial);
  if (!tty)
    tty = match_dev(product, serial);
  if (product && product != arg)
    free(product);
  return tty;
}


x86 assembly (clang, -O0):
<cc_usbdevs_find_by_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123d <cc_usbdevs_find_by_arg+0xed>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11b5 <cc_usbdevs_find_by_arg+0x65>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a8 <cc_usbdevs_find_by_arg+0x58>
movq   $0x0,-0x8(%rbp)
jmp    12bf <cc_usbdevs_find_by_arg+0x16f>
movq   $0x0,-0x20(%rbp)
jmp    1238 <cc_usbdevs_find_by_arg+0xe8>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1224 <cc_usbdevs_find_by_arg+0xd4>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     121f <cc_usbdevs_find_by_arg+0xcf>
movq   $0x0,-0x8(%rbp)
jmp    12bf <cc_usbdevs_find_by_arg+0x16f>
jmp    1233 <cc_usbdevs_find_by_arg+0xe3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    1238 <cc_usbdevs_find_by_arg+0xe8>
jmp    124c <cc_usbdevs_find_by_arg+0xfc>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127a <cc_usbdevs_find_by_arg+0x12a>
cmpq   $0x0,-0x18(%rbp)
je     127a <cc_usbdevs_find_by_arg+0x12a>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <match_dev@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1295 <cc_usbdevs_find_by_arg+0x145>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <match_dev@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12b7 <cc_usbdevs_find_by_arg+0x167>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     12b7 <cc_usbdevs_find_by_arg+0x167>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_usbdevs_find_by_arg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     118e <cc_usbdevs_find_by_arg+0x3e>
mov    %rsp,%rsi
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     1196 <cc_usbdevs_find_by_arg+0x46>
xor    %r12d,%r12d
cmpb   $0x0,(%rcx)
je     11dc <cc_usbdevs_find_by_arg+0x8c>
xor    %ebp,%ebp
jmp    1237 <cc_usbdevs_find_by_arg+0xe7>
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    11df <cc_usbdevs_find_by_arg+0x8f>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11fe <cc_usbdevs_find_by_arg+0xae>
mov    %rax,%r13
mov    %r13d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1050 <strndup@plt>
mov    %rax,%r12
add    $0x1,%r13
mov    %rsp,%rsi
xor    %ebp,%ebp
mov    %r13,%rdi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r15d
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1237 <cc_usbdevs_find_by_arg+0xe7>
jmp    11df <cc_usbdevs_find_by_arg+0x8f>
mov    %eax,%r15d
test   %r14,%r14
je     1217 <cc_usbdevs_find_by_arg+0xc7>
test   %r12,%r12
jne    1217 <cc_usbdevs_find_by_arg+0xc7>
mov    %r14,%rdi
mov    %r15d,%esi
call   1070 <match_dev@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1237 <cc_usbdevs_find_by_arg+0xe7>
xor    %ebx,%ebx
mov    %rbx,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <match_dev@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1070 <match_dev@plt>
mov    %rax,%rbp
test   %r12,%r12
je     1237 <cc_usbdevs_find_by_arg+0xe7>
cmp    %rbx,%r12
je     1237 <cc_usbdevs_find_by_arg+0xe7>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @cc_usbdevs_find_by_arg(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %53
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strtol(i8* %14, i8** %8, i32 0)
store i32 %15, i32* %7
%16 = load i8*, i8** %8
%17 = load i8*, i8** %4
%18 = icmp ne i8* %16, %17
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i8* null, i8** %3
br label %83
25: ; preds = %19
store i8* null, i8** %6
br label %52
26: ; preds = %13
%27 = load i8*, i8** %4
%28 = call i8* @strchr(i8* %27, i8 signext 58)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %49
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i8*, i8** %9
%34 = load i8*, i8** %4
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = call i8* @strndup(i8* %32, i32 %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @strtol(i8* %41, i8** %8, i32 0)
store i32 %42, i32* %7
%43 = load i8*, i8** %8
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %31
store i8* null, i8** %3
br label %83
48: ; preds = %31
br label %51
49: ; preds = %26
%50 = load i8*, i8** %4
store i8* %50, i8** %6
store i32 0, i32* %7
br label %51
51: ; preds = %49, %48
br label %52
52: ; preds = %51, %25
br label %54
53: ; preds = %2
store i8* null, i8** %6
store i32 0, i32* %7
br label %54
54: ; preds = %53, %52
store i8* null, i8** %10
%55 = load i8*, i8** %6
%56 = icmp ne i8* %55, null
br i1 %56, label %64, label %57
57: ; preds = %54
%58 = load i8*, i8** %5
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i8*, i8** %5
%62 = load i32, i32* %7
%63 = call i8* @match_dev(i8* %61, i32 %62)
store i8* %63, i8** %10
br label %64
64: ; preds = %60, %57, %54
%65 = load i8*, i8** %10
%66 = icmp ne i8* %65, null
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = load i8*, i8** %6
%69 = load i32, i32* %7
%70 = call i8* @match_dev(i8* %68, i32 %69)
store i8* %70, i8** %10
br label %71
71: ; preds = %67, %64
%72 = load i8*, i8** %6
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %81
74: ; preds = %71
%75 = load i8*, i8** %6
%76 = load i8*, i8** %4
%77 = icmp ne i8* %75, %76
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i8*, i8** %6
%80 = call i32 @free(i8* %79)
br label %81
81: ; preds = %78, %74, %71
%82 = load i8*, i8** %10
store i8* %82, i8** %3
br label %83
83: ; preds = %81, %47, %24
%84 = load i8*, i8** %3
ret i8* %84
}

LLVM IR (-O2):
define i8* @cc_usbdevs_find_by_arg(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = call i32 @strtol(i8* %0, i8** %3, i32 0)
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, %0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %27, label %46
13: ; preds = %6
%14 = tail call i8* @strchr(i8* %0, i8 signext 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %36, label %16
16: ; preds = %13
%17 = ptrtoint i8* %14 to i64
%18 = ptrtoint i8* %0 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i8* @strndup(i8* %0, i32 %20)
%22 = getelementptr inbounds i8, i8* %14, i64 1
%23 = call i32 @strtol(i8* %22, i8** %3, i32 0)
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %2, %10, %16
%28 = phi i8* [ %21, %16 ], [ null, %10 ], [ null, %2 ]
%29 = phi i32 [ %23, %16 ], [ %7, %10 ], [ 0, %2 ]
%30 = icmp eq i8* %28, null
%31 = icmp ne i8* %1, null
%32 = and i1 %31, %30
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = tail call i8* @match_dev(i8* %1, i32 %29)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %46
36: ; preds = %33, %13
%37 = phi i8* [ %0, %13 ], [ null, %33 ]
%38 = phi i32 [ 0, %13 ], [ %29, %33 ]
%39 = tail call i8* @match_dev(i8* %37, i32 %38)
br label %46
40: ; preds = %27
%41 = tail call i8* @match_dev(i8* %28, i32 %29)
%42 = icmp eq i8* %28, %0
%43 = or i1 %30, %42
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = tail call i32 @free(i8* %28)
br label %46
46: ; preds = %33, %36, %40, %44, %16, %10
%47 = phi i8* [ null, %10 ], [ null, %16 ], [ %41, %44 ], [ %41, %40 ], [ %39, %36 ], [ %34, %33 ]
ret i8* %47
}