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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int sscanf(char *, char *, int *, int *);
int msx_readval2(char *fn, int *val1, int *val2) {
  int fd = open(fn, 0);
  int r;
  char num[30];
  if (fd == -1)
    return (0);
  num[sizeof(num) - 1] = '\0';
  r = read(fd, num, sizeof(num) - 1);
  close(fd);
  if (r < 0)
    return (0);
  r = sscanf(num, "%d %d", val1, val2);
  if (r == 1)
    *val2 = 0;
  else if (r != 2)
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<msx_readval2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1178 <msx_readval2+0x38>
movl   $0x0,-0x4(%rbp)
jmp    1204 <msx_readval2+0xc4>
movb   $0x0,-0x33(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1d,%edx
call   1040 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x28(%rbp)
jge    11ae <msx_readval2+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    1204 <msx_readval2+0xc4>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe3f(%rip),%rsi
call   1050 <sscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11e2 <msx_readval2+0xa2>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    11fd <msx_readval2+0xbd>
cmpl   $0x2,-0x28(%rbp)
je     11f8 <msx_readval2+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    1204 <msx_readval2+0xc4>
jmp    11fd <msx_readval2+0xbd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msx_readval2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
xor    %r12d,%r12d
xor    %esi,%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b0 <msx_readval2+0x70>
mov    %eax,%ebp
movb   $0x0,0x1d(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1d,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
test   %ebx,%ebx
js     11b0 <msx_readval2+0x70>
lea    0xe75(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
je     11aa <msx_readval2+0x6a>
cmp    $0x1,%eax
jne    11b0 <msx_readval2+0x70>
movl   $0x0,(%r14)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
define i32 @msx_readval2(i8* nocapture %0, i32* %1, i32* %2) {
%4 = alloca [30 x i8]
%5 = tail call i32 @open(i8* %0, i32 0)
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %5, -1
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 29
store i8 0, i8* %9
%10 = call i32 @read(i32 %5, i8* %6, i32 29)
%11 = tail call i32 @close(i32 %5)
%12 = icmp slt i32 %10, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
switch i32 %14, label %17 [
i32 1, label %15
i32 2, label %16
]
15: ; preds = %13
store i32 0, i32* %2
br label %16
16: ; preds = %13, %15
br label %17
17: ; preds = %13, %8, %3, %16
%18 = phi i32 [ 1, %16 ], [ 0, %3 ], [ 0, %8 ], [ 0, %13 ]
ret i32 %18
}