#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char *const *, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ stderr;
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
void parseOpts(int argc, char *const argv[], char *tty) {
  int opt;
  while ((opt = getopt(argc, argv, "d:")) != -1) {
    switch (opt) {
    case 'd':
      if (256 <= strlen(optarg)) {
        fprintf(stderr, "[Error] string entry for option -d too long\n");
        exit(EXIT_FAILURE);
      } else {
        strncpy(tty, optarg, 256);
      }
      break;
    default:
      fprintf(stderr, "Usage %s -d /dev/<serial device>\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<parseOpts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1222 <parseOpts+0xd2>
mov    -0x1c(%rbp),%eax
sub    $0x64,%eax
jne    11f1 <parseOpts+0xa1>
jmp    1193 <parseOpts+0x43>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x100,%eax
cmp    %ecx,%eax
jg     11d5 <parseOpts+0x85>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    121d <parseOpts+0xcd>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1163 <parseOpts+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseOpts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe99(%rip),%r15
mov    0x2e8a(%rip),%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x64,%eax
jne    11a1 <parseOpts+0x51>
mov    (%rbx),%edi
call   1040 <strlen@plt>
cmp    $0x100,%eax
jge    11af <parseOpts+0x5f>
mov    (%rbx),%esi
mov    %r12,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    1170 <parseOpts+0x20>
cmp    $0xffffffff,%eax
jne    11c8 <parseOpts+0x78>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11e2 <parseOpts+0x92>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe55(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"d:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"[Error] string entry for option -d too long\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [34 x i8] c"Usage %s -d /dev/<serial device>\0A\00"
define void @parseOpts(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
br label %8
8: ; preds = %37, %3
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %7
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = load i32, i32* %7
switch i32 %14, label %29 [
i32 100, label %15
]
15: ; preds = %13
%16 = load i32, i32* @optarg
%17 = call i32 @strlen(i32 %16)
%18 = icmp sle i32 256, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = load i32, i32* @optarg
%27 = call i32 @strncpy(i8* %25, i32 %26, i32 256)
br label %28
28: ; preds = %24
br label %37
29: ; preds = %13
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"d:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"[Error] string entry for option -d too long\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [34 x i8] c"Usage %s -d /dev/<serial device>\0A\00"
define void @parseOpts(i32 %0, i8** %1, i8* %2) {
br label %4
4: ; preds = %15, %3
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %18 [
i32 -1, label %24
i32 100, label %6
]
6: ; preds = %4
%7 = load i32, i32* @optarg
%8 = tail call i32 @strlen(i32 %7)
%9 = icmp sgt i32 %8, 255
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %6
%16 = load i32, i32* @optarg
%17 = tail call i32 @strncpy(i8* %2, i32 %16, i32 256)
br label %4
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %4
ret void
}