#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ get_at(int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ str_check_symbol(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ str_replace(char *, char *, int, char *, char *);
int get_coverage(int module_id, char *h, int cmds_id) {
  char buf[1024];
  int coverage = -1, ber = -1;
  if (!str_check_symbol(get_at(module_id, cmds_id), buf, sizeof(buf)))
    return -1;
  if (!str_replace(buf, buf, sizeof(buf), "$COVERAGE", "%d"))
    return -1;
  if (!str_replace(buf, buf, sizeof(buf), "$BER", "%d"))
    return -1;
  sscanf(h, buf, &coverage, &ber);
  return coverage;
}


x86 assembly (clang, -O0):
<get_coverage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x424(%rbp)
ff ff ff
movl   $0xffffffff,-0x428(%rbp)
ff ff ff
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <get_at@plt>
mov    %eax,%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <str_check_symbol@plt>
cmp    $0x0,%eax
jne    119c <get_coverage+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <get_coverage+0xf9>
lea    -0x420(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
lea    0xe4a(%rip),%rcx
lea    0xe4d(%rip),%r8
call   1030 <str_replace@plt>
cmp    $0x0,%eax
jne    11d7 <get_coverage+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <get_coverage+0xf9>
lea    -0x420(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
lea    0xe1c(%rip),%rcx
lea    0xe12(%rip),%r8
call   1030 <str_replace@plt>
cmp    $0x0,%eax
jne    1212 <get_coverage+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <get_coverage+0xf9>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x424(%rbp),%rdx
lea    -0x428(%rbp),%rcx
call   1040 <sscanf@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_coverage>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0xc(%rsp)
ff
mov    %edx,%esi
call   1060 <get_at@plt>
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <str_check_symbol@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     11e0 <get_coverage+0xa0>
lea    0xe7c(%rip),%rcx
lea    0xe7f(%rip),%r8
lea    0x10(%rsp),%rdi
mov    %rdi,%rsi
mov    $0x400,%edx
call   1030 <str_replace@plt>
test   %eax,%eax
je     11e0 <get_coverage+0xa0>
lea    0xe65(%rip),%rcx
lea    0xe5b(%rip),%r8
lea    0x10(%rsp),%rdi
mov    %rdi,%rsi
mov    $0x400,%edx
call   1030 <str_replace@plt>
test   %eax,%eax
je     11e0 <get_coverage+0xa0>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    0x8(%rsp),%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"$COVERAGE\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"$BER\00"
define i32 @get_coverage(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%9 = bitcast i32* %6 to i8*
store i32 -1, i32* %6
%10 = tail call i32 @get_at(i32 %0, i32 %2)
%11 = call i32 @str_check_symbol(i32 %10, i8* %7, i32 1024)
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %3
%14 = call i32 @str_replace(i8* %7, i8* %7, i32 1024, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i32 @str_replace(i8* %7, i8* %7, i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 @sscanf(i8* %1, i8* %7, i32* %5, i32* %6)
%21 = load i32, i32* %5
br label %22
22: ; preds = %16, %13, %3, %19
%23 = phi i32 [ %21, %19 ], [ -1, %3 ], [ -1, %13 ], [ -1, %16 ]
ret i32 %23
}