#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(char *, char *);
char *strtok(char *, char *);
int read_frontend_uevent(char *uevent, int *device, int *adapter) {
  char uf_name[64];
  FILE *ufile;
  char line[128];
  char *token = NULL;
  sprintf(uf_name, "%s/%s", uevent, "uevent");
  ufile = fopen(uf_name, "r");
  if (ufile == NULL) {
    fprintf(stderr, "File: %s open failed\n", uf_name);
    return -1;
  }
  while (1) {
    if (fgets(line, sizeof(line), ufile) == NULL)
      return -1;
    if (strstr(line, "DVB_ADAPTER_NUM")) {
      token = strtok(line, "=");
      token = strtok(NULL, "=");
      *adapter = atoi(token);
    }
    if (strstr(line, "DVB_DEVICE_NUM")) {
      token = strtok(line, "=");
      token = strtok(NULL, "=");
      *device = atoi(token);
    }
  }
  fclose(ufile);
  return 0;
}


x86 assembly (clang, -O0):
<read_frontend_uevent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0xf8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
lea    0xe5e(%rip),%rcx
call   1080 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11f1 <read_frontend_uevent+0x81>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xe2f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <read_frontend_uevent+0x17a>
jmp    11f6 <read_frontend_uevent+0x86>
lea    -0xf0(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x80,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    1221 <read_frontend_uevent+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <read_frontend_uevent+0x17a>
lea    -0xf0(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1283 <read_frontend_uevent+0x113>
lea    -0xf0(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xf8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd2(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0xf0(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12e5 <read_frontend_uevent+0x175>
lea    -0xf0(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xf8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd70(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f6 <read_frontend_uevent+0x86>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_frontend_uevent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%rdx
lea    0xe6d(%rip),%rsi
lea    0xe6c(%rip),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     127f <read_frontend_uevent+0x10f>
mov    %rax,%r13
lea    0x50(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     1299 <read_frontend_uevent+0x129>
lea    0xe41(%rip),%r12
lea    0x50(%rsp),%rbx
lea    0xe47(%rip),%rbp
lea    0xe3e(%rip),%r14
jmp    1219 <read_frontend_uevent+0xa9>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r13,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     1299 <read_frontend_uevent+0x129>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     124d <read_frontend_uevent+0xdd>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1200 <read_frontend_uevent+0x90>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r15)
jmp    1200 <read_frontend_uevent+0x90>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [7 x i8] c"uevent\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"File: %s open failed\0A\00"
@.str.4 = [16 x i8] c"DVB_ADAPTER_NUM\00"
@.str.5 = [2 x i8] c"=\00"
@.str.6 = [15 x i8] c"DVB_DEVICE_NUM\00"
define i32 @read_frontend_uevent(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [64 x i8]
%9 = alloca i32*
%10 = alloca [128 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* null, i8** %11
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %21)
store i32 -1, i32* %4
br label %53
23: ; preds = %3
br label %24
24: ; preds = %23, %52
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%26 = load i32*, i32** %9
%27 = call i32* @fgets(i8* %25, i32 128, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %4
br label %53
30: ; preds = %24
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%32 = call i64 @strstr(i8* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%36 = call i8* @strtok(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %36, i8** %11
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %37, i8** %11
%38 = load i8*, i8** %11
%39 = call i32 @atoi(i8* %38)
%40 = load i32*, i32** %7
store i32 %39, i32* %40
br label %41
41: ; preds = %34, %30
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%43 = call i64 @strstr(i8* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%47 = call i8* @strtok(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %47, i8** %11
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = call i32 @atoi(i8* %49)
%51 = load i32*, i32** %6
store i32 %50, i32* %51
br label %52
52: ; preds = %45, %41
br label %24
53: ; preds = %29, %19
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [7 x i8] c"uevent\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"File: %s open failed\0A\00"
@.str.4 = [16 x i8] c"DVB_ADAPTER_NUM\00"
@.str.5 = [2 x i8] c"=\00"
@.str.6 = [15 x i8] c"DVB_DEVICE_NUM\00"
define i32 @read_frontend_uevent(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [64 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = call i32* @fgets(i8* %7, i32 128, i32* %9)
%13 = icmp eq i32* %12, null
br i1 %13, label %34, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %34
17: ; preds = %11, %31
%18 = call i64 @strstr(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %17
%25 = call i64 @strstr(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %1
br label %31
31: ; preds = %27, %24
%32 = call i32* @fgets(i8* %7, i32 128, i32* %9)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %17
34: ; preds = %31, %11, %14
ret i32 -1
}