#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 */
struct hdhomerun_device_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ hdhomerun_device_set_tuner(struct hdhomerun_device_t *,
                                              unsigned int);
int sscanf(char const *, char *, unsigned int *);
int hdhomerun_device_set_tuner_from_str(struct hdhomerun_device_t *hd,
                                        const char *tuner_str) {
  unsigned int tuner;
  if (sscanf(tuner_str, "%u", &tuner) == 1) {
    hdhomerun_device_set_tuner(hd, tuner);
    return 1;
  }
  if (sscanf(tuner_str, "/tuner%u", &tuner) == 1) {
    hdhomerun_device_set_tuner(hd, tuner);
    return 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<hdhomerun_device_set_tuner_from_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xecb(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    1165 <hdhomerun_device_set_tuner_from_str+0x45>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <hdhomerun_device_set_tuner@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <hdhomerun_device_set_tuner_from_str+0x81>
mov    -0x18(%rbp),%rdi
lea    0xe90(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    119a <hdhomerun_device_set_tuner_from_str+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <hdhomerun_device_set_tuner@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <hdhomerun_device_set_tuner_from_str+0x81>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdhomerun_device_set_tuner_from_str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xed5(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1163 <hdhomerun_device_set_tuner_from_str+0x43>
lea    0xeb6(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    1174 <hdhomerun_device_set_tuner_from_str+0x54>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <hdhomerun_device_set_tuner@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hdhomerun_device_t = type { i32 }
@.str = [3 x i8] c"%u\00"
@.str.1 = [9 x i8] c"/tuner%u\00"
define i32 @hdhomerun_device_set_tuner_from_str(%struct.hdhomerun_device_t* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.hdhomerun_device_t*
%5 = alloca i8*
%6 = alloca i32
store %struct.hdhomerun_device_t* %0, %struct.hdhomerun_device_t** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load %struct.hdhomerun_device_t*, %struct.hdhomerun_device_t** %4
%12 = load i32, i32* %6
%13 = call i32 @hdhomerun_device_set_tuner(%struct.hdhomerun_device_t* %11, i32 %12)
store i32 1, i32* %3
br label %23
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load %struct.hdhomerun_device_t*, %struct.hdhomerun_device_t** %4
%20 = load i32, i32* %6
%21 = call i32 @hdhomerun_device_set_tuner(%struct.hdhomerun_device_t* %19, i32 %20)
store i32 1, i32* %3
br label %23
22: ; preds = %14
store i32 -1, i32* %3
br label %23
23: ; preds = %22, %18, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.hdhomerun_device_t = type { i32 }
@.str = [3 x i8] c"%u\00"
@.str.1 = [9 x i8] c"/tuner%u\00"
define i32 @hdhomerun_device_set_tuner_from_str(%struct.hdhomerun_device_t* %0, i8* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load i32, i32* %3
%12 = call i32 @hdhomerun_device_set_tuner(%struct.hdhomerun_device_t* %0, i32 %11)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ -1, %7 ], [ 1, %10 ]
ret i32 %14
}