#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();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int parse_args(int argc, char **argv, uint32_t *gpio_address, 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, "a:w:m:r")) != -1) {
    switch (par) {
    case 'a':
      *gpio_address = strtoul(optarg, NULL, 0);
      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    0xee7(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     125c <parse_args+0x11c>
mov    -0x34(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x16,%eax
ja     1235 <parse_args+0xf5>
mov    -0x40(%rbp),%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1257 <parse_args+0x117>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
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    1257 <parse_args+0x117>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
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    1257 <parse_args+0x117>
mov    0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1257 <parse_args+0x117>
mov    -0x34(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <howto@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <parse_args+0x123>
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    0xef1(%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    -0x61(%rax),%ecx
cmp    $0x16,%ecx
ja     1201 <parse_args+0xc1>
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    (%r12),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,0x0(%r13)
jmp    118b <parse_args+0x4b>
nopl   0x0(%rax)
mov    (%r12),%edi
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),%edi
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    0xe53(%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"a:w:m:r\00"
@optarg = global i32 0
@.str.1 = [28 x i8] c"%c: parametro sconosciuto.\0A\00"
define i32 @parse_args(i32 %0, i8** %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i32*
%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 i32* %2, i32** %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 = %46, %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 %47
24: ; preds = %19
%25 = load i32, i32* %18
switch i32 %25, label %42 [
i32 97, label %26
i32 119, label %30
i32 109, label %35
i32 114, label %40
]
26: ; preds = %24
%27 = load i32, i32* @optarg
%28 = call i32 @strtoul(i32 %27, i32* null, i32 0)
%29 = load i32*, i32** %12
store i32 %28, i32* %29
br label %46
30: ; preds = %24
%31 = load i32, i32* @optarg
%32 = call i32 @strtoul(i32 %31, i32* null, i32 0)
%33 = load i32*, i32** %16
store i32 %32, i32* %33
%34 = load i32*, i32** %15
store i32 1, i32* %34
br label %46
35: ; preds = %24
%36 = load i32, i32* @optarg
%37 = call i32 @strtoul(i32 %36, i32* null, i32 0)
%38 = load i32*, i32** %14
store i32 %37, i32* %38
%39 = load i32*, i32** %13
store i32 1, i32* %39
br label %46
40: ; preds = %24
%41 = load i32*, i32** %17
store i32 1, i32* %41
br label %46
42: ; preds = %24
%43 = load i32, i32* %18
%44 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = call i32 (...) @howto()
store i32 -1, i32* %9
br label %48
46: ; preds = %40, %35, %30, %26
br label %19
47: ; preds = %19
store i32 0, i32* %9
br label %48
48: ; preds = %47, %42
%49 = load i32, i32* %9
ret i32 %49
}

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