#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 getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int sys_getopt(int argc, char **argv, char *opts, char *opt_arg,
               int opt_arg_size) {
  int opt;
  if (!opts || !opt_arg) {
    return -1;
  }
  opt = getopt(argc, argv, opts);
  snprintf(opt_arg, opt_arg_size, "%s", (optarg) ? optarg : "");
  return opt;
}


x86 assembly (clang, -O0):
<sys_getopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1151 <sys_getopt+0x31>
cmpq   $0x0,-0x20(%rbp)
jne    115d <sys_getopt+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <sys_getopt+0xaf>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e73(%rip),%rax
cmpq   $0x0,(%rax)
je     11a2 <sys_getopt+0x82>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    11b2 <sys_getopt+0x92>
lea    0xe59(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11b2 <sys_getopt+0x92>
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rcx
lea    0xe3c(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_getopt>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     116a <sys_getopt+0x4a>
mov    %rcx,%rbx
test   %rcx,%rcx
je     116a <sys_getopt+0x4a>
mov    %r8d,%ebp
call   1040 <getopt@plt>
mov    %eax,%r14d
mov    0x2eb5(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
lea    0xeb2(%rip),%rcx
cmovne %rax,%rcx
lea    0xea5(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <snprintf@plt>
mov    %r14d,%eax
jmp    116f <sys_getopt+0x4f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@optarg = global i8* null
@.str.1 = [1 x i8] zeroinitializer
define i32 @sys_getopt(i32 %0, i8** %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %7
store i8** %1, i8*** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %5
store i32 -1, i32* %6
br label %35
19: ; preds = %15
%20 = load i32, i32* %7
%21 = load i8**, i8*** %8
%22 = load i8*, i8** %9
%23 = call i32 @getopt(i32 %20, i8** %21, i8* %22)
store i32 %23, i32* %12
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = load i8*, i8** @optarg
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load i8*, i8** @optarg
br label %31
30: ; preds = %19
br label %31
31: ; preds = %30, %28
%32 = phi i8* [ %29, %28 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %30 ]
%33 = call i32 @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %12
store i32 %34, i32* %6
br label %35
35: ; preds = %31, %18
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@optarg = global i8* null
@.str.1 = [1 x i8] zeroinitializer
define i32 @sys_getopt(i32 %0, i8** %1, i8* %2, i8* %3, i32 %4) {
%6 = icmp ne i8* %2, null
%7 = icmp ne i8* %3, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* %2)
%11 = load i8*, i8** @optarg
%12 = icmp eq i8* %11, null
%13 = select i1 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %11
%14 = tail call i32 @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %5, %9
%16 = phi i32 [ %10, %9 ], [ -1, %5 ]
ret i32 %16
}