#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int getopt(int, char **, char *);
int /*<<< orphan*/ howto();
char *optarg;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int parse_args(int argc, char **argv, char **uio, uint8_t *op_mode,
               uint32_t *mode_value, uint8_t *op_write, uint32_t *write_value,
               uint8_t *op_read) {
  int par;
  while ((par = getopt(argc, argv, "d:w:m:r")) != -1) {
    switch (par) {
    case 'd':
      *uio = optarg;
      break;
    case 'w':
      *write_value = strtoul(optarg, NULL, 0);
      *op_write = 1;
      break;
    case 'm':
      *mode_value = strtoul(optarg, NULL, 0);
      *op_mode = 1;
      break;
    case 'r':
      *op_read = 1;
      break;
    default:
      printf("%c: parametro sconosciuto.\n", par);
      howto();
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xedb(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1253 <parse_args+0x113>
mov    -0x34(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x13,%eax
ja     122c <parse_args+0xec>
mov    -0x40(%rbp),%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e42(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    124e <parse_args+0x10e>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
jmp    124e <parse_args+0x10e>
mov    0x2e00(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    124e <parse_args+0x10e>
mov    0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    124e <parse_args+0x10e>
mov    -0x34(%rbp),%esi
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <howto@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <parse_args+0x11a>
jmp    1167 <parse_args+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,0x8(%rsp)
mov    %rcx,(%rsp)
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xee5(%rip),%r14
lea    0xe8e(%rip),%r15
mov    0x2e7f(%rip),%r12
jmp    118b <parse_args+0x4b>
nopl   0x0(%rax,%rax,1)
mov    0x58(%rsp),%rax
movl   $0x1,(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
lea    -0x64(%rax),%ecx
cmp    $0x13,%ecx
ja     1201 <parse_args+0xc1>
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    (%r12),%rax
mov    %rax,0x0(%r13)
jmp    118b <parse_args+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
mov    (%rsp),%rax
movl   $0x1,(%rax)
jmp    118b <parse_args+0x4b>
mov    (%r12),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    0x50(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x10(%rsp),%rax
movl   $0x1,(%rax)
jmp    118b <parse_args+0x4b>
cmp    $0xffffffff,%eax
jne    120a <parse_args+0xca>
xor    %eax,%eax
jmp    1224 <parse_args+0xe4>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <howto@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"d:w:m:r\00"
@optarg = global i8* null
@.str.1 = [28 x i8] c"%c: parametro sconosciuto.\0A\00"
define i32 @parse_args(i32 %0, i8** %1, i8** %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
store i32 %0, i32* %10
store i8** %1, i8*** %11
store i8** %2, i8*** %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
br label %19
19: ; preds = %45, %8
%20 = load i32, i32* %10
%21 = load i8**, i8*** %11
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %18
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %46
24: ; preds = %19
%25 = load i32, i32* %18
switch i32 %25, label %41 [
i32 100, label %26
i32 119, label %29
i32 109, label %34
i32 114, label %39
]
26: ; preds = %24
%27 = load i8*, i8** @optarg
%28 = load i8**, i8*** %12
store i8* %27, i8** %28
br label %45
29: ; preds = %24
%30 = load i8*, i8** @optarg
%31 = call i32 @strtoul(i8* %30, i32* null, i32 0)
%32 = load i32*, i32** %16
store i32 %31, i32* %32
%33 = load i32*, i32** %15
store i32 1, i32* %33
br label %45
34: ; preds = %24
%35 = load i8*, i8** @optarg
%36 = call i32 @strtoul(i8* %35, i32* null, i32 0)
%37 = load i32*, i32** %14
store i32 %36, i32* %37
%38 = load i32*, i32** %13
store i32 1, i32* %38
br label %45
39: ; preds = %24
%40 = load i32*, i32** %17
store i32 1, i32* %40
br label %45
41: ; preds = %24
%42 = load i32, i32* %18
%43 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 (...) @howto()
store i32 -1, i32* %9
br label %47
45: ; preds = %39, %34, %29, %26
br label %19
46: ; preds = %19
store i32 0, i32* %9
br label %47
47: ; preds = %46, %41
%48 = load i32, i32* %9
ret i32 %48
}

LLVM IR (-O2):
@.str = [8 x i8] c"d:w:m:r\00"
@optarg = global i8* null
@.str.1 = [28 x i8] c"%c: parametro sconosciuto.\0A\00"
define i32 @parse_args(i32 %0, i8** %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i32* nocapture writeonly %7) {
br label %9
9: ; preds = %20, %8
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %21 [
i32 -1, label %24
i32 100, label %11
i32 119, label %13
i32 109, label %16
i32 114, label %19
]
11: ; preds = %9
%12 = load i8*, i8** @optarg
store i8* %12, i8** %2
br label %20
13: ; preds = %9
%14 = load i8*, i8** @optarg
%15 = tail call i32 @strtoul(i8* nocapture %14, i32* null, i32 0)
store i32 %15, i32* %6
store i32 1, i32* %5
br label %20
16: ; preds = %9
%17 = load i8*, i8** @optarg
%18 = tail call i32 @strtoul(i8* nocapture %17, i32* null, i32 0)
store i32 %18, i32* %4
store i32 1, i32* %3
br label %20
19: ; preds = %9
store i32 1, i32* %7
br label %20
20: ; preds = %19, %16, %13, %11
br label %9
21: ; preds = %9
%22 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%23 = tail call i32 (...) @howto()
br label %24
24: ; preds = %9, %21
%25 = phi i32 [ -1, %21 ], [ 0, %9 ]
ret i32 %25
}