#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 EINVAL;
int sscanf(char const *, char *, char *, ...);
int /*<<< orphan*/ strncpy(char *, char *, int);
int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode) {
  int r;
  if (sscanf(nameAndMode,
             "%"
             "32"
             "[^-]-%"
             "32"
             "s",
             name, mode) != 2) {
    if ((r = sscanf(nameAndMode,
                    "%"
                    "32"
                    "[^-]",
                    name)) == 1)
      strncpy(mode, "cbc-plain", 10);
    else
      return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_into_name_and_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
cmp    $0x2,%eax
je     11ab <parse_into_name_and_mode+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x1,%eax
jne    1193 <parse_into_name_and_mode+0x73>
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
jmp    11a6 <parse_into_name_and_mode+0x86>
xor    %eax,%eax
mov    0x2e44(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <parse_into_name_and_mode+0x92>
jmp    11ab <parse_into_name_and_mode+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_into_name_and_mode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xec9(%rip),%rsi
xor    %r15d,%r15d
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x2,%eax
je     1188 <parse_into_name_and_mode+0x68>
lea    0xeba(%rip),%rsi
xor    %r15d,%r15d
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    117e <parse_into_name_and_mode+0x5e>
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1030 <strncpy@plt>
jmp    1188 <parse_into_name_and_mode+0x68>
mov    0x2e5b(%rip),%rax
sub    (%rax),%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%32[^-]-%32s\00"
@.str.1 = [8 x i8] c"%32[^-]\00"
@.str.2 = [10 x i8] c"cbc-plain\00"
@EINVAL = global i32 0
define i32 @parse_into_name_and_mode(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = load i8*, i8** %7
%12 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %26
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 %17, i32* %8
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 10)
br label %25
22: ; preds = %14
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
store i32 %24, i32* %4
br label %27
25: ; preds = %19
br label %26
26: ; preds = %25, %3
store i32 0, i32* %4
br label %27
27: ; preds = %26, %22
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [13 x i8] c"%32[^-]-%32s\00"
@.str.1 = [8 x i8] c"%32[^-]\00"
@.str.2 = [10 x i8] c"cbc-plain\00"
@EINVAL = global i32 0
define i32 @parse_into_name_and_mode(i8* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%5 = icmp eq i32 %4, 2
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 10)
br label %14
11: ; preds = %6
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
br label %14
14: ; preds = %3, %9, %11
%15 = phi i32 [ %13, %11 ], [ 0, %9 ], [ 0, %3 ]
ret i32 %15
}