#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*/ debugf_fn(char *, int, char *, ...);
int /*<<< orphan*/ ppm_device_close(int);
int ppm_device_open(char const *);
int ppm_ver_fd(int, int *, int *);
int ppm_ver(const char *fname, int *ver, int *rev) {
  int fd, ret;
  if ((fd = ppm_device_open(fname)) == -1) {
    debugf_fn("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/geekysuavo/pyppm/refs/heads/main/"
              "software/core/ppm-hw.c",
              427, "failed to open device file");
    return 0;
  }
  ret = ppm_ver_fd(fd, ver, rev);
  ppm_device_close(fd);
  if (ret)
    debugf_fn("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/geekysuavo/pyppm/refs/heads/main/"
              "software/core/ppm-hw.c",
              441, "VER: %d.%d OK", *ver, *rev);
  else
    debugf_fn("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/geekysuavo/pyppm/refs/heads/main/"
              "software/core/ppm-hw.c",
              443, "VER: ERR");
  return ret;
}


x86 assembly (clang, -O0):
<ppm_ver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ppm_device_open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    118f <ppm_ver+0x4f>
lea    0xe90(%rip),%rdi
mov    $0x1ab,%esi
lea    0xf16(%rip),%rdx
mov    $0x0,%al
call   1060 <debugf_fn@plt>
movl   $0x0,-0x4(%rbp)
jmp    1200 <ppm_ver+0xc0>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <ppm_ver_fd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <ppm_device_close@plt>
cmpl   $0x0,-0x28(%rbp)
je     11e0 <ppm_ver+0xa0>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8d
lea    0xe38(%rip),%rdi
mov    $0x1b9,%esi
lea    0xed9(%rip),%rdx
mov    $0x0,%al
call   1060 <debugf_fn@plt>
jmp    11fa <ppm_ver+0xba>
lea    0xe19(%rip),%rdi
mov    $0x1bb,%esi
lea    0xec8(%rip),%rdx
mov    $0x0,%al
call   1060 <debugf_fn@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppm_ver>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1050 <ppm_device_open@plt>
cmp    $0xffffffff,%eax
je     1196 <ppm_ver+0x56>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <ppm_ver_fd@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1030 <ppm_device_close@plt>
test   %r15d,%r15d
je     11ae <ppm_ver+0x6e>
mov    (%rbx),%ecx
mov    (%r14),%r8d
lea    0xe7f(%rip),%rdi
lea    0xf25(%rip),%rdx
mov    $0x1b9,%esi
xor    %eax,%eax
call   1060 <debugf_fn@plt>
jmp    11cb <ppm_ver+0x8b>
lea    0xe63(%rip),%rdi
lea    0xeee(%rip),%rdx
xor    %r15d,%r15d
mov    $0x1ab,%esi
jmp    11c4 <ppm_ver+0x84>
lea    0xe4b(%rip),%rdi
lea    0xeff(%rip),%rdx
xor    %r15d,%r15d
mov    $0x1bb,%esi
xor    %eax,%eax
call   1060 <debugf_fn@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/geekysuavo/pyppm/refs/heads/main/software/core/ppm-hw.c\00"
@.str.1 = [27 x i8] c"failed to open device file\00"
@.str.2 = [14 x i8] c"VER: %d.%d OK\00"
@.str.3 = [9 x i8] c"VER: ERR\00"
define i32 @ppm_ver(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i32 @ppm_device_open(i8* %10)
store i32 %11, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 427, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %34
15: ; preds = %3
%16 = load i32, i32* %8
%17 = load i32*, i32** %6
%18 = load i32*, i32** %7
%19 = call i32 @ppm_ver_fd(i32 %16, i32* %17, i32* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %8
%21 = call i32 @ppm_device_close(i32 %20)
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %15
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = load i32*, i32** %7
%28 = load i32, i32* %27
%29 = call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 441, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %28)
br label %32
30: ; preds = %15
%31 = call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 443, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %13
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/geekysuavo/pyppm/refs/heads/main/software/core/ppm-hw.c\00"
@.str.1 = [27 x i8] c"failed to open device file\00"
@.str.2 = [14 x i8] c"VER: %d.%d OK\00"
@.str.3 = [9 x i8] c"VER: ERR\00"
define i32 @ppm_ver(i8* %0, i32* %1, i32* %2) {
%4 = tail call i32 @ppm_device_open(i8* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 427, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %18
8: ; preds = %3
%9 = tail call i32 @ppm_ver_fd(i32 %4, i32* %1, i32* %2)
%10 = tail call i32 @ppm_device_close(i32 %4)
%11 = icmp eq i32 %9, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = tail call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 441, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
br label %18
16: ; preds = %8
%17 = tail call i32 (i8*, i32, i8*, ...) @debugf_fn(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 443, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %12, %16, %6
%19 = phi i32 [ 0, %6 ], [ 0, %16 ], [ %9, %12 ]
ret i32 %19
}