#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 */
char *my_realpath(char const *, char *);
int strncmp(char const *, char *, int);
int strtol(char const *, char **, int);
int parse_device(const char *devicename_) {
  char devicenamebuf[4096];
  const char *devicename = my_realpath(devicename_, devicenamebuf);
  int ret = strncmp(devicename, "/dev/video", 10);
  const char *device = (ret) ? devicename : (devicename + 10);
  char *endptr = 0;
  int dev = strtol(device, &endptr, 10);
  if (!*endptr)
    return dev;
  return -1;
}


x86 assembly (clang, -O0):
<parse_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1050 <my_realpath@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
je     1194 <parse_device+0x64>
mov    -0x1018(%rbp),%rax
mov    %rax,-0x1040(%rbp)
jmp    11a6 <parse_device+0x76>
mov    -0x1018(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x1040(%rbp)
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1028(%rbp)
movq   $0x0,-0x1030(%rbp)
mov    -0x1028(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1034(%rbp)
mov    -0x1030(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11fb <parse_device+0xcb>
mov    -0x1034(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <parse_device+0xd2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_device>:
push   %rbx
sub    $0x1010,%rsp
lea    0x10(%rsp),%rsi
call   1050 <my_realpath@plt>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
lea    0xa(%rbx),%rdi
test   %eax,%eax
cmovne %rbx,%rdi
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ecx,%ecx
or     %ecx,%eax
add    $0x1010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/video\00"
define i32 @parse_device(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4096 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%12 = call i8* @my_realpath(i8* %10, i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = load i8*, i8** %5
br label %22
19: ; preds = %1
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 10
br label %22
22: ; preds = %19, %17
%23 = phi i8* [ %18, %17 ], [ %21, %19 ]
store i8* %23, i8** %7
store i8* null, i8** %8
%24 = load i8*, i8** %7
%25 = call i32 @strtol(i8* %24, i8** %8, i32 10)
store i32 %25, i32* %9
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %22
%30 = load i32, i32* %9
store i32 %30, i32* %2
br label %32
31: ; preds = %22
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %29
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/video\00"
define i32 @parse_device(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = call i8* @my_realpath(i8* %0, i8* %4)
%6 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i64 10, i64 0
%9 = getelementptr i8, i8* %5, i64 %8
%10 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%11 = call i32 @strtol(i8* %9, i8** %3, i32 10)
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = select i1 %14, i32 %11, i32 -1
ret i32 %15
}