#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*/ exit(int);
int /*<<< orphan*/ getTTYMappedName(char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("bad arguments \n");
    printf("--------------------------------------------------\n");
    printf("Usage : tty_mapper Product\n");
    printf("--------------------------------------------------\n");
    printf(
        "Return the first matching tty associated to a specific productId\n");
    printf("Product can be found in dmesg or /var/log/messages\n");
    printf("examples: \n");
    printf(" - localhost kernel: usb 2-1.3: \n");
    printf("   New USB device strings: Mfr=1, Product=2, SerialNumber=3\n");
    printf("          localhost kernel: usb 2-1.3: Product: SAMSUNG_Android\n");
    printf("    command is : tty_mapper \"ttyUSB\" \"SAMSUNG_Android\"\n");
    exit(1);
  }
  char res[255];
  getTTYMappedName(argv[1], argv[2], res);
  printf("%s\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f7 <main+0xc7>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x110(%rbp),%rdx
call   1050 <getTTYMappedName@plt>
lea    -0x110(%rbp),%rsi
lea    0xf99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x3,%edi
jne    1163 <main+0x33>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
call   1050 <getTTYMappedName@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xf20(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
lea    0xf64(%rip),%rdi
call   1030 <puts@plt>
lea    0xf98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"bad arguments \0A\00"
@.str.1 = [52 x i8] c"--------------------------------------------------\0A\00"
@.str.2 = [28 x i8] c"Usage : tty_mapper Product\0A\00"
@.str.3 = [66 x i8] c"Return the first matching tty associated to a specific productId\0A\00"
@.str.4 = [52 x i8] c"Product can be found in dmesg or /var/log/messages\0A\00"
@.str.5 = [12 x i8] c"examples: \0A\00"
@.str.6 = [34 x i8] c" - localhost kernel: usb 2-1.3: \0A\00"
@.str.7 = [61 x i8] c" New USB device strings: Mfr=1, Product=2, SerialNumber=3\0A\00"
@.str.8 = [65 x i8] c" localhost kernel: usb 2-1.3: Product: SAMSUNG_Android\0A\00"
@.str.9 = [56 x i8] c" command is : tty_mapper \22ttyUSB\22 \22SAMSUNG_Android\22\0A\00"
@.str.10 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.8, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%30 = call i32 @getTTYMappedName(i8* %25, i8* %28, i8* %29)
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %31)
ret i32 0
}

LLVM IR (-O2):
@str = [15 x i8] c"bad arguments \00"
@str.12 = [27 x i8] c"Usage : tty_mapper Product\00"
@str.13 = [51 x i8] c"--------------------------------------------------\00"
@str.14 = [65 x i8] c"Return the first matching tty associated to a specific productId\00"
@str.15 = [51 x i8] c"Product can be found in dmesg or /var/log/messages\00"
@str.16 = [11 x i8] c"examples: \00"
@str.17 = [33 x i8] c" - localhost kernel: usb 2-1.3: \00"
@str.18 = [60 x i8] c" New USB device strings: Mfr=1, Product=2, SerialNumber=3\00"
@str.19 = [64 x i8] c" localhost kernel: usb 2-1.3: Product: SAMSUNG_Android\00"
@str.20 = [55 x i8] c" command is : tty_mapper \22ttyUSB\22 \22SAMSUNG_Android\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.13, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.12, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.13, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.14, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.15, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.17, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.18, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.19, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.20, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @getTTYMappedName(i8* %21, i8* %23, i8* %19)
%25 = call i32 @puts(i8* %19)
ret i32 0
}