#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 EXIT_SUCCESS;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char getopt(int, char **, char *);
char *malloc(int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char opt;
  int cFlag = 0, vFlag = 0, bFlag = 0, fFlag = 0;
  int bOpt = 0;
  char *fOpt = NULL;
  int i = 0, j = 0;
  while ((opt = getopt(argc, argv, "cvb:f:")) != -1) {
    switch (opt) {
    case 'c':
      cFlag = 1;
      break;
    case 'v':
      vFlag = 1;
      break;
    case 'b':
      bFlag = 1;
      bOpt = atoi(optarg);
      break;
    case 'f':
      fFlag = 1;
      if ((fOpt = malloc(strlen(optarg) * sizeof(char))) == NULL) {
        do {
          perror("malloc failed for fOpt");
          exit(EXIT_FAILURE);
        } while (0);
      }
      strcpy(fOpt, optarg);
      break;
    default:
      exit(EXIT_FAILURE);
    }
  }
  if (cFlag) {
    printf("Found option c\n");
  }
  if (vFlag) {
    printf("Found option v\n");
  }
  if (bFlag) {
    printf("Found option b with value: %d\n", bOpt);
  }
  if (fFlag) {
    printf("Found option f with value: %s\n", fOpt);
  }
  i = optind;
  j = argc - optind;
  while (j) {
    printf("Found non-option argument: %s\n", argv[i]);
    i++;
    j--;
  }
  free(fOpt);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12d9 <main+0x149>
movsbl -0x11(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x14,%eax
ja     12c6 <main+0x136>
mov    -0x40(%rbp),%rax
lea    0xdde(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    12d4 <main+0x144>
movl   $0x1,-0x1c(%rbp)
jmp    12d4 <main+0x144>
movl   $0x1,-0x20(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    12d4 <main+0x144>
movl   $0x1,-0x24(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12af <main+0x11f>
jmp    1295 <main+0x105>
lea    0xdbf(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
jmp    12d4 <main+0x144>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    11df <main+0x4f>
cmpl   $0x0,-0x18(%rbp)
je     12f1 <main+0x161>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1309 <main+0x179>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
je     1324 <main+0x194>
mov    -0x28(%rbp),%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
je     1340 <main+0x1b0>
mov    -0x30(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2c8a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1396 <main+0x206>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    135b <main+0x1cb>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
lea    0xe9c(%rip),%rdx
mov    %rsi,0x20(%rsp)
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     1307 <main+0x167>
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
lea    0xe28(%rip),%rbp
lea    0xe75(%rip),%r15
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %r13d,%r13d
jmp    122f <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x1,0x8(%rsp)
mov    %r12d,%r13d
mov    %r14d,%edi
mov    0x20(%rsp),%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     12aa <main+0x10a>
movsbl %al,%eax
add    $0xffffff9e,%eax
cmp    $0x14,%eax
ja     1372 <main+0x1d2>
mov    %r13d,%r12d
mov    $0x1,%r13d
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %rax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
jmp    1218 <main+0x78>
xchg   %ax,%ax
mov    0x2d81(%rip),%rbx
mov    (%rbx),%edi
call   1060 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1366 <main+0x1c6>
mov    (%rbx),%esi
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
call   1040 <strcpy@plt>
movl   $0x1,0x4(%rsp)
jmp    1218 <main+0x78>
test   %r13d,%r13d
je     12bb <main+0x11b>
lea    0xe28(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x8(%rsp)
mov    0x18(%rsp),%r13
je     12d3 <main+0x133>
lea    0xe01(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     12ed <main+0x14d>
lea    0xd91(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x4(%rsp)
je     130a <main+0x16a>
lea    0xd96(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    130a <main+0x16a>
xor    %r13d,%r13d
mov    0x2ccf(%rip),%rax
movslq (%rax),%rax
sub    %eax,%r14d
je     1346 <main+0x1a6>
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,8),%r12
mov    %r14d,%ebp
lea    0xd84(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1330 <main+0x190>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcee(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"cvb:f:\00"
@optarg = global i32 0
@.str.1 = [23 x i8] c"malloc failed for fOpt\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [16 x i8] c"Found option c\0A\00"
@.str.3 = [16 x i8] c"Found option v\0A\00"
@.str.4 = [31 x i8] c"Found option b with value: %d\0A\00"
@.str.5 = [31 x i8] c"Found option f with value: %s\0A\00"
@optind = global i32 0
@.str.6 = [31 x i8] c"Found non-option argument: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i8* null, i8** %12
store i32 0, i32* %13
store i32 0, i32* %14
br label %15
15: ; preds = %50, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call signext i8 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 %18, i8* %6
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %51
21: ; preds = %15
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
switch i32 %23, label %47 [
i32 99, label %24
i32 118, label %25
i32 98, label %26
i32 102, label %29
]
24: ; preds = %21
store i32 1, i32* %7
br label %50
25: ; preds = %21
store i32 1, i32* %8
br label %50
26: ; preds = %21
store i32 1, i32* %9
%27 = load i32, i32* @optarg
%28 = call i32 @atoi(i32 %27)
store i32 %28, i32* %11
br label %50
29: ; preds = %21
store i32 1, i32* %10
%30 = load i32, i32* @optarg
%31 = call i32 @strlen(i32 %30)
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %12
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %43
37: ; preds = %29
br label %38
38: ; preds = %37
%39 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; No predecessors!
br label %43
43: ; preds = %42, %29
%44 = load i8*, i8** %12
%45 = load i32, i32* @optarg
%46 = call i32 @strcpy(i8* %44, i32 %45)
br label %50
47: ; preds = %21
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43, %26, %25, %24
br label %15
51: ; preds = %15
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %11
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %61
%68 = load i32, i32* %10
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i8*, i8** %12
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %71)
br label %73
73: ; preds = %70, %67
%74 = load i32, i32* @optind
store i32 %74, i32* %13
%75 = load i32, i32* %4
%76 = load i32, i32* @optind
%77 = sub nsw i32 %75, %76
store i32 %77, i32* %14
br label %78
78: ; preds = %81, %73
%79 = load i32, i32* %14
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %92
81: ; preds = %78
%82 = load i8**, i8*** %5
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %86)
%88 = load i32, i32* %13
%89 = add nsw i32 %88, 1
store i32 %89, i32* %13
%90 = load i32, i32* %14
%91 = add nsw i32 %90, -1
store i32 %91, i32* %14
br label %78
92: ; preds = %78
%93 = load i8*, i8** %12
%94 = call i32 @free(i8* %93)
%95 = load i32, i32* @EXIT_SUCCESS
ret i32 %95
}

LLVM IR (-O2):
@.str = [7 x i8] c"cvb:f:\00"
@optarg = global i32 0
@.str.1 = [23 x i8] c"malloc failed for fOpt\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [31 x i8] c"Found option b with value: %d\0A\00"
@.str.5 = [31 x i8] c"Found option f with value: %s\0A\00"
@optind = global i32 0
@.str.6 = [31 x i8] c"Found non-option argument: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"Found option v\00"
@str.7 = [15 x i8] c"Found option c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %58, label %5
5: ; preds = %2, %33
%6 = phi i8 [ %40, %33 ], [ %3, %2 ]
%7 = phi i8* [ %39, %33 ], [ null, %2 ]
%8 = phi i32 [ %38, %33 ], [ 0, %2 ]
%9 = phi i32 [ %37, %33 ], [ 0, %2 ]
%10 = phi i32 [ %36, %33 ], [ 0, %2 ]
%11 = phi i32 [ %35, %33 ], [ 0, %2 ]
%12 = phi i32 [ %34, %33 ], [ 0, %2 ]
%13 = sext i8 %6 to i32
switch i32 %13, label %30 [
i32 99, label %33
i32 118, label %14
i32 98, label %15
i32 102, label %18
]
14: ; preds = %5
br label %33
15: ; preds = %5
%16 = load i32, i32* @optarg
%17 = tail call i32 @atoi(i32 %16)
br label %33
18: ; preds = %5
%19 = load i32, i32* @optarg
%20 = tail call i32 @strlen(i32 %19)
%21 = tail call i8* @malloc(i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = load i32, i32* @optarg
%29 = tail call i32 @strcpy(i8* %21, i32 %28)
br label %33
30: ; preds = %5
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %5, %27, %15, %14
%34 = phi i32 [ %12, %27 ], [ %12, %15 ], [ %12, %14 ], [ 1, %5 ]
%35 = phi i32 [ %11, %27 ], [ %11, %15 ], [ 1, %14 ], [ %11, %5 ]
%36 = phi i32 [ %10, %27 ], [ 1, %15 ], [ %10, %14 ], [ %10, %5 ]
%37 = phi i32 [ 1, %27 ], [ %9, %15 ], [ %9, %14 ], [ %9, %5 ]
%38 = phi i32 [ %8, %27 ], [ %17, %15 ], [ %8, %14 ], [ %8, %5 ]
%39 = phi i8* [ %21, %27 ], [ %7, %15 ], [ %7, %14 ], [ %7, %5 ]
%40 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%41 = icmp eq i8 %40, -1
br i1 %41, label %42, label %5
42: ; preds = %33
%43 = icmp eq i32 %34, 0
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = icmp eq i32 %35, 0
br i1 %47, label %50, label %48
48: ; preds = %46
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = icmp eq i32 %36, 0
br i1 %51, label %54, label %52
52: ; preds = %50
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %54
54: ; preds = %52, %50
%55 = icmp eq i32 %37, 0
br i1 %55, label %58, label %56
56: ; preds = %54
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %39)
br label %58
58: ; preds = %2, %56, %54
%59 = phi i8* [ %39, %56 ], [ %39, %54 ], [ null, %2 ]
%60 = load i32, i32* @optind
%61 = sub nsw i32 %0, %60
%62 = icmp eq i32 %61, 0
br i1 %62, label %74, label %63
63: ; preds = %58
%64 = sext i32 %60 to i64
br label %65
65: ; preds = %63, %65
%66 = phi i64 [ %64, %63 ], [ %71, %65 ]
%67 = phi i32 [ %61, %63 ], [ %72, %65 ]
%68 = getelementptr inbounds i8*, i8** %1, i64 %66
%69 = load i8*, i8** %68
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = add nsw i64 %66, 1
%72 = add nsw i32 %67, -1
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %65
74: ; preds = %65, %58
%75 = tail call i32 @free(i8* %59)
%76 = load i32, i32* @EXIT_SUCCESS
ret i32 %76
}