#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 scan_mode(char *, long *, int /*<<< orphan*/ *);
int sscanf(char *, char *, char *, char *);
int scan_modes(char *attr_str, long *majorp, long *minorp) {
  long val1, val2 = 0;
  char buf1[18], buf2[18];
  int rc;
  if ((rc = sscanf(attr_str, "%17s\n%17s", buf1, buf2)) <= 0)
    return -1;
  if (rc == 2 && scan_mode(buf2, &val2, NULL) != 1)
    return -1;
  if (scan_mode(buf1, &val1, NULL) != 1)
    return -1;
  *majorp = val1 | val2;
  return 1;
}


x86 assembly (clang, -O0):
<scan_modes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    0xeae(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jg     116f <scan_modes+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <scan_modes+0xbb>
cmpl   $0x2,-0x74(%rbp)
jne    119f <scan_modes+0x7f>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <scan_mode@plt>
cmp    $0x1,%eax
je     119f <scan_modes+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <scan_modes+0xbb>
lea    -0x50(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <scan_mode@plt>
cmp    $0x1,%eax
je     11c5 <scan_modes+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <scan_modes+0xbb>
mov    -0x28(%rbp),%rcx
or     -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_modes>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
movq   $0x0,(%rsp)
lea    0xec8(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <sscanf@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jle    1190 <scan_modes+0x70>
cmp    $0x2,%eax
jne    1169 <scan_modes+0x49>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <scan_mode@plt>
cmp    $0x1,%eax
jne    1190 <scan_modes+0x70>
lea    0x30(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <scan_mode@plt>
cmp    $0x1,%eax
jne    1190 <scan_modes+0x70>
mov    (%rsp),%rax
or     0x8(%rsp),%rax
mov    %rax,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"%17s\0A%17s\00"
define i32 @scan_modes(i8* nocapture %0, i64* nocapture writeonly %1, i64* nocapture readnone %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca [18 x i8]
%7 = alloca [18 x i8]
%8 = bitcast i64* %4 to i8*
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%10 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %26, label %14
14: ; preds = %3
%15 = icmp eq i32 %12, 2
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = call i32 @scan_mode(i8* %11, i64* %5, i32* null)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %26
19: ; preds = %16, %14
%20 = call i32 @scan_mode(i8* %10, i64* %4, i32* null)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i64, i64* %4
%24 = load i64, i64* %5
%25 = or i64 %24, %23
store i64 %25, i64* %1
br label %26
26: ; preds = %19, %16, %3, %22
%27 = phi i32 [ 1, %22 ], [ -1, %3 ], [ -1, %16 ], [ -1, %19 ]
ret i32 %27
}