#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 berictl_pause(struct beri_debug *);
int berictl_setpc(struct beri_debug *, char *);
int berictl_stream_trace(struct beri_debug *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int berictl_test_run(struct beri_debug *bdp) {
  int ret;
  char pc[20];
  strcpy(pc, "9000000040000000");
  ret = berictl_pause(bdp);
  printf("Draining trace buffer:\n");
  ret = berictl_stream_trace(bdp, 1, 0, 0);
  if (ret != 0)
    return (ret);
  ret = berictl_setpc(bdp, pc);
  if (ret != 0)
    return (ret);
  int streamTimes = 16;
  int binary = 0;
  ret = berictl_stream_trace(bdp, streamTimes, binary, 0);
  if (ret != 0)
    return (ret);
  return (berictl_pause(bdp));
}


x86 assembly (clang, -O0):
<berictl_test_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <berictl_pause@plt>
mov    %eax,-0x14(%rbp)
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <berictl_stream_trace@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ae <berictl_test_run+0x5e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <berictl_test_run+0xc6>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <berictl_setpc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d3 <berictl_test_run+0x83>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <berictl_test_run+0xc6>
movl   $0x10,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
xor    %ecx,%ecx
call   1060 <berictl_stream_trace@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     120a <berictl_test_run+0xba>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <berictl_test_run+0xc6>
mov    -0x10(%rbp),%rdi
call   1050 <berictl_pause@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<berictl_test_run>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <berictl_pause@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <berictl_stream_trace@plt>
test   %eax,%eax
jne    11bc <berictl_test_run+0x6c>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <berictl_setpc@plt>
test   %eax,%eax
jne    11bc <berictl_test_run+0x6c>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <berictl_stream_trace@plt>
test   %eax,%eax
jne    11bc <berictl_test_run+0x6c>
mov    %rbx,%rdi
call   1050 <berictl_pause@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.beri_debug = type { i32 }
@.str = [17 x i8] c"9000000040000000\00"
@.str.1 = [24 x i8] c"Draining trace buffer:\0A\00"
define i32 @berictl_test_run(%struct.beri_debug* %0) {
%2 = alloca i32
%3 = alloca %struct.beri_debug*
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = alloca i32
store %struct.beri_debug* %0, %struct.beri_debug** %3
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = load %struct.beri_debug*, %struct.beri_debug** %3
%11 = call i32 @berictl_pause(%struct.beri_debug* %10)
store i32 %11, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%13 = load %struct.beri_debug*, %struct.beri_debug** %3
%14 = call i32 @berictl_stream_trace(%struct.beri_debug* %13, i32 1, i32 0, i32 0)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %39
19: ; preds = %1
%20 = load %struct.beri_debug*, %struct.beri_debug** %3
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%22 = call i32 @berictl_setpc(%struct.beri_debug* %20, i8* %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %39
27: ; preds = %19
store i32 16, i32* %6
store i32 0, i32* %7
%28 = load %struct.beri_debug*, %struct.beri_debug** %3
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @berictl_stream_trace(%struct.beri_debug* %28, i32 %29, i32 %30, i32 0)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %39
36: ; preds = %27
%37 = load %struct.beri_debug*, %struct.beri_debug** %3
%38 = call i32 @berictl_pause(%struct.beri_debug* %37)
store i32 %38, i32* %2
br label %39
39: ; preds = %36, %34, %25, %17
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.beri_debug = type { i32 }
@.str = [17 x i8] c"9000000040000000\00"
@str = [23 x i8] c"Draining trace buffer:\00"
define i32 @berictl_test_run(%struct.beri_debug* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @berictl_pause(%struct.beri_debug* %0)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%7 = call i32 @berictl_stream_trace(%struct.beri_debug* %0, i32 1, i32 0, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = call i32 @berictl_setpc(%struct.beri_debug* %0, i8* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = call i32 @berictl_stream_trace(%struct.beri_debug* %0, i32 16, i32 0, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @berictl_pause(%struct.beri_debug* %0)
br label %17
17: ; preds = %15, %12, %9, %1
%18 = phi i32 [ %7, %1 ], [ %10, %9 ], [ %16, %15 ], [ %13, %12 ]
ret i32 %18
}