#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 */
struct beri_debug {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ beri_debug_client_close(struct beri_debug *);
int beri_debug_client_open(struct beri_debug **, int);
int beri_debug_client_open_path(struct beri_debug **, char const *, int);
char *beri_debug_strerror(int);
int berictl_docontrol(struct beri_debug *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct beri_debug *bdp = NULL;
  const char *filep = NULL, *controlp = NULL, *pathp = NULL;
  int opt, ret;
  while ((opt = getopt(argc, argv, "c:f:p")) != -1) {
    switch (opt) {
    case 'c':
      controlp = optarg;
      break;
    case 'f':
      filep = optarg;
      break;
    case 'p':
      pathp = optarg;
      break;
    default:
      usage();
    }
  }
  argc -= optind;
  argv += optind;
  if (argc != 0) {
    usage();
  }
  if (pathp != NULL)
    ret = beri_debug_client_open_path(&bdp, pathp, 0x00000000);
  else
    ret = beri_debug_client_open(&bdp, 0x00000000);
  if (ret != 0) {
    fprintf(stderr, "Failure opening debugging session: %s\n",
            beri_debug_strerror(ret));
    exit(EXIT_FAILURE);
  }
  if (filep == NULL && 0) {
    fprintf(stderr, "Expecting test file");
    usage();
  }
  if (controlp == NULL) {
    fprintf(stderr, "Expecting Control file");
    usage();
  }
  ret = berictl_docontrol(bdp, controlp);
  fprintf(stderr, "DONE WITH CONTROL SEQUENCE");
  if (ret == (-1)) {
    usage();
  }
  if (ret != 0) {
    fprintf(stderr, "Failure applying operation: %s\n",
            beri_debug_strerror(ret));
    exit(EXIT_FAILURE);
  }
  beri_debug_client_close(bdp);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1260 <main+0xd0>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x63,%eax
je     121b <main+0x8b>
jmp    11f9 <main+0x69>
mov    -0x3c(%rbp),%eax
sub    $0x66,%eax
je     122e <main+0x9e>
jmp    120a <main+0x7a>
mov    -0x3c(%rbp),%eax
sub    $0x70,%eax
je     1241 <main+0xb1>
jmp    1254 <main+0xc4>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    125b <main+0xcb>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    125b <main+0xcb>
mov    0x2db0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    125b <main+0xcb>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11c6 <main+0x36>
mov    0x2d79(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     129b <main+0x10b>
mov    $0x0,%al
call   1080 <usage@plt>
cmpq   $0x0,-0x30(%rbp)
je     12bd <main+0x12d>
mov    -0x30(%rbp),%rsi
lea    -0x18(%rbp),%rdi
xor    %edx,%edx
call   1070 <beri_debug_client_open_path@plt>
mov    %eax,-0x38(%rbp)
jmp    12cb <main+0x13b>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <beri_debug_client_open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     130b <main+0x17b>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <beri_debug_strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1343 <main+0x1b3>
xor    %eax,%eax
test   $0x1,%al
jne    1325 <main+0x195>
jmp    1343 <main+0x1b3>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
cmpq   $0x0,-0x28(%rbp)
jne    136c <main+0x1dc>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
lea    0xce3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <berictl_docontrol@plt>
mov    %eax,-0x38(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xccc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpl   $0xffffffff,-0x38(%rbp)
jne    13a4 <main+0x214>
mov    $0x0,%al
call   1080 <usage@plt>
cmpl   $0x0,-0x38(%rbp)
je     13e4 <main+0x254>
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <beri_debug_strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xca4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <beri_debug_client_close@plt>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,(%rsp)
lea    0xe51(%rip),%r12
mov    0x2e42(%rip),%r13
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11cc <main+0x3c>
xchg   %ax,%ax
cmp    $0x70,%eax
je     11fc <main+0x6c>
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
cmp    $0x65,%eax
jle    11f0 <main+0x60>
cmp    $0x66,%eax
je     11cc <main+0x3c>
jmp    11c0 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x63,%eax
je     1202 <main+0x72>
cmp    $0xffffffff,%eax
jne    11c5 <main+0x35>
jmp    1208 <main+0x78>
mov    0x0(%r13),%r15
jmp    11cc <main+0x3c>
mov    0x0(%r13),%r14
jmp    11cc <main+0x3c>
mov    0x2dd1(%rip),%rax
cmp    %ebp,(%rax)
je     121a <main+0x8a>
xor    %eax,%eax
call   1080 <usage@plt>
mov    %rsp,%rdi
test   %r15,%r15
jne    1248 <main+0xb8>
xor    %esi,%esi
call   1060 <beri_debug_client_open@plt>
test   %eax,%eax
je     1256 <main+0xc6>
mov    0x2d9c(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <beri_debug_strerror@plt>
lea    0xdc2(%rip),%rsi
mov    %ebx,%edi
jmp    12c2 <main+0x132>
mov    %r15,%rsi
xor    %edx,%edx
call   1070 <beri_debug_client_open_path@plt>
test   %eax,%eax
jne    122d <main+0x9d>
test   %r14,%r14
jne    1279 <main+0xe9>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1080 <usage@plt>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1030 <berictl_docontrol@plt>
mov    %eax,%ebx
mov    0x2d42(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdac(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebx,%ebx
je     12da <main+0x14a>
cmp    $0xffffffff,%ebx
jne    12af <main+0x11f>
xor    %eax,%eax
call   1080 <usage@plt>
mov    0x0(%rbp),%ebp
mov    %ebx,%edi
call   1050 <beri_debug_strerror@plt>
lea    0xd9f(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    (%rsp),%rdi
call   10a0 <beri_debug_client_close@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.beri_debug = type { i32 }
@.str = [6 x i8] c"c:f:p\00"
@optarg = global i8* null
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"Failure opening debugging session: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [20 x i8] c"Expecting test file\00"
@.str.3 = [23 x i8] c"Expecting Control file\00"
@.str.4 = [27 x i8] c"DONE WITH CONTROL SEQUENCE\00"
@.str.5 = [32 x i8] c"Failure applying operation: %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 %struct.beri_debug*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.beri_debug* null, %struct.beri_debug** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %10
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32, i32* %10
switch i32 %18, label %25 [
i32 99, label %19
i32 102, label %21
i32 112, label %23
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %8
br label %27
21: ; preds = %17
%22 = load i8*, i8** @optarg
store i8* %22, i8** %7
br label %27
23: ; preds = %17
%24 = load i8*, i8** @optarg
store i8* %24, i8** %9
br label %27
25: ; preds = %17
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %25, %23, %21, %19
br label %12
28: ; preds = %12
%29 = load i64, i64* @optind
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = sub nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
%34 = load i64, i64* @optind
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 %34
store i8** %36, i8*** %5
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %28
%40 = call i32 (...) @usage()
br label %41
41: ; preds = %39, %28
%42 = load i8*, i8** %9
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %9
%46 = call i32 @beri_debug_client_open_path(%struct.beri_debug** %6, i8* %45, i32 0)
store i32 %46, i32* %11
br label %49
47: ; preds = %41
%48 = call i32 @beri_debug_client_open(%struct.beri_debug** %6, i32 0)
store i32 %48, i32* %11
br label %49
49: ; preds = %47, %44
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i32, i32* %11
%55 = call i8* @beri_debug_strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %49
%60 = load i8*, i8** %7
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %67
62: ; preds = %59
br i1 false, label %63, label %67
63: ; preds = %62
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%66 = call i32 (...) @usage()
br label %67
67: ; preds = %63, %62, %59
%68 = load i8*, i8** %8
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 (...) @usage()
br label %74
74: ; preds = %70, %67
%75 = load %struct.beri_debug*, %struct.beri_debug** %6
%76 = load i8*, i8** %8
%77 = call i32 @berictl_docontrol(%struct.beri_debug* %75, i8* %76)
store i32 %77, i32* %11
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* %11
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %84
82: ; preds = %74
%83 = call i32 (...) @usage()
br label %84
84: ; preds = %82, %74
%85 = load i32, i32* %11
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %84
%88 = load i32, i32* @stderr
%89 = load i32, i32* %11
%90 = call i8* @beri_debug_strerror(i32 %89)
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %90)
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %84
%95 = load %struct.beri_debug*, %struct.beri_debug** %6
%96 = call i32 @beri_debug_client_close(%struct.beri_debug* %95)
%97 = load i32, i32* @EXIT_SUCCESS
%98 = call i32 @exit(i32 %97)
unreachable
}

LLVM IR (-O2):
%struct.beri_debug = type { i32 }
@.str = [6 x i8] c"c:f:p\00"
@optarg = global i8* null
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"Failure opening debugging session: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [23 x i8] c"Expecting Control file\00"
@.str.4 = [27 x i8] c"DONE WITH CONTROL SEQUENCE\00"
@.str.5 = [32 x i8] c"Failure applying operation: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.beri_debug*
%4 = bitcast %struct.beri_debug** %3 to i8*
store %struct.beri_debug* null, %struct.beri_debug** %3
br label %5
5: ; preds = %13, %2
%6 = phi i8* [ %14, %13 ], [ null, %2 ]
%7 = phi i8* [ %9, %13 ], [ null, %2 ]
br label %8
8: ; preds = %5, %15
%9 = phi i8* [ %7, %5 ], [ %16, %15 ]
br label %10
10: ; preds = %12, %8
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %17 [
i32 -1, label %19
i32 99, label %13
i32 102, label %12
i32 112, label %15
]
12: ; preds = %10, %17
br label %10
13: ; preds = %10
%14 = load i8*, i8** @optarg
br label %5
15: ; preds = %10
%16 = load i8*, i8** @optarg
br label %8
17: ; preds = %10
%18 = tail call i32 (...) @usage()
br label %12
19: ; preds = %10
%20 = load i64, i64* @optind
%21 = trunc i64 %20 to i32
%22 = icmp eq i32 %21, %0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 (...) @usage()
br label %25
25: ; preds = %23, %19
%26 = icmp eq i8* %9, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = call i32 @beri_debug_client_open_path(%struct.beri_debug** %3, i8* %9, i32 0)
br label %31
29: ; preds = %25
%30 = call i32 @beri_debug_client_open(%struct.beri_debug** %3, i32 0)
br label %31
31: ; preds = %29, %27
%32 = phi i32 [ %28, %27 ], [ %30, %29 ]
%33 = icmp eq i32 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i8* @beri_debug_strerror(i32 %32)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %31
%41 = icmp eq i8* %6, null
br i1 %41, label %42, label %46
42: ; preds = %40
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 (...) @usage()
br label %46
46: ; preds = %42, %40
%47 = load %struct.beri_debug*, %struct.beri_debug** %3
%48 = call i32 @berictl_docontrol(%struct.beri_debug* %47, i8* %6)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
switch i32 %48, label %53 [
i32 -1, label %51
i32 0, label %59
]
51: ; preds = %46
%52 = call i32 (...) @usage()
br label %53
53: ; preds = %51, %46
%54 = load i32, i32* @stderr
%55 = call i8* @beri_debug_strerror(i32 %48)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %46
%60 = load %struct.beri_debug*, %struct.beri_debug** %3
%61 = call i32 @beri_debug_client_close(%struct.beri_debug* %60)
%62 = load i32, i32* @EXIT_SUCCESS
%63 = call i32 @exit(i32 %62)
unreachable
}