#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 media_device {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int setup_link(struct media_device *, char const *, char **);
int setup_links(struct media_device *media, const char *p) {
  char *end;
  int ret;
  do {
    ret = setup_link(media, p, &end);
    if (ret < 0)
      return ret;
    p = end + 1;
  } while (*end == ',');
  return *end ? -EINVAL : 0;
}


x86 assembly (clang, -O0):
<setup_links>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <setup_link@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1149 <setup_links+0x39>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <setup_links+0x88>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1120 <setup_links+0x10>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <setup_links+0x78>
xor    %eax,%eax
mov    0x2e62(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <setup_links+0x82>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <setup_links+0x82>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_links>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <setup_link@plt>
test   %eax,%eax
js     1151 <setup_links+0x41>
mov    (%rsp),%rsi
movzbl (%rsi),%ecx
add    $0x1,%rsi
cmp    $0x2c,%cl
je     1120 <setup_links+0x10>
mov    0x2e9a(%rip),%rdx
xor    %eax,%eax
sub    (%rdx),%eax
xor    %edx,%edx
test   %cl,%cl
cmove  %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.media_device = type { i32 }
@EINVAL = global i32 0
define i32 @setup_links(%struct.media_device* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.media_device*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store %struct.media_device* %0, %struct.media_device** %4
store i8* %1, i8** %5
br label %8
8: ; preds = %19, %2
%9 = load %struct.media_device*, %struct.media_device** %4
%10 = load i8*, i8** %5
%11 = call i32 @setup_link(%struct.media_device* %9, i8* %10, i8** %6)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = load i32, i32* %7
store i32 %15, i32* %3
br label %35
16: ; preds = %8
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %5
br label %19
19: ; preds = %16
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 44
br i1 %23, label %8, label %24
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @EINVAL
%31 = sub nsw i32 0, %30
br label %33
32: ; preds = %24
br label %33
33: ; preds = %32, %29
%34 = phi i32 [ %31, %29 ], [ 0, %32 ]
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %14
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.media_device = type { i32 }
@EINVAL = global i32 0
define i32 @setup_links(%struct.media_device* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
br label %5
5: ; preds = %9, %2
%6 = phi i8* [ %1, %2 ], [ %11, %9 ]
%7 = call i32 @setup_link(%struct.media_device* %0, i8* %6, i8** %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 44
br i1 %13, label %5, label %14
14: ; preds = %9
%15 = icmp eq i8 %12, 0
%16 = load i32, i32* @EINVAL
%17 = sub nsw i32 0, %16
%18 = select i1 %15, i32 0, i32 %17
br label %19
19: ; preds = %5, %14
%20 = phi i32 [ %18, %14 ], [ %7, %5 ]
ret i32 %20
}