#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 utsname {
  char *sysname;
  char *release;
  char *machine;
};
typedef int ssize_t;

/* Variables and functions */
int if_machinearch(char *, size_t);
int snprintf(char *, size_t, char *, char *, char *, ...);
scalar_t__ uname(struct utsname *);
ssize_t dhcp_vendor(char *str, size_t len) {
  struct utsname utn;
  char *p;
  int l;
  if (uname(&utn) != 0)
    return (ssize_t)snprintf(str, len, "%s-%s", "dhcpcd", "6.7.1");
  p = str;
  l = snprintf(p, len, "%s-%s:%s-%s:%s", "dhcpcd", "6.7.1", utn.sysname,
               utn.release, utn.machine);
  if (l == -1 || (size_t)(l + 1) > len)
    return -1;
  p += l;
  len -= (size_t)l;
  l = if_machinearch(p, len);
  if (l == -1 || (size_t)(l + 1) > len)
    return -1;
  p += l;
  return p - str;
}


x86 assembly (clang, -O0):
<dhcp_vendor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0x0,%rax
je     117f <dhcp_vendor+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe9e(%rip),%rdx
lea    0xe9d(%rip),%rcx
lea    0xe9d(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1262 <dhcp_vendor+0x132>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x20(%rbp),%rax
lea    0xe71(%rip),%rdx
lea    0xe5d(%rip),%rcx
lea    0xe5d(%rip),%r8
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
je     11df <dhcp_vendor+0xaf>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
cmp    -0x18(%rbp),%rax
jbe    11eb <dhcp_vendor+0xbb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <dhcp_vendor+0x132>
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movslq -0x3c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <if_machinearch@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
je     1237 <dhcp_vendor+0x107>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
cmp    -0x18(%rbp),%rax
jbe    1243 <dhcp_vendor+0x113>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <dhcp_vendor+0x132>
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhcp_vendor>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
call   1050 <uname@plt>
test   %rax,%rax
je     117b <dhcp_vendor+0x4b>
lea    0xeaa(%rip),%rdx
lea    0xea9(%rip),%rcx
lea    0xea9(%rip),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <snprintf@plt>
mov    0x10(%rsp),%r9
movups 0x18(%rsp),%xmm0
movups %xmm0,(%rsp)
lea    0xe83(%rip),%rdx
lea    0xe6f(%rip),%rcx
lea    0xe6f(%rip),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11ed <dhcp_vendor+0xbd>
lea    0x1(%rax),%ecx
movslq %ecx,%rcx
cmp    %rbx,%rcx
ja     11ed <dhcp_vendor+0xbd>
cltq
lea    (%r14,%rax,1),%r15
sub    %rax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <if_machinearch@plt>
cmp    $0xffffffff,%eax
je     11ed <dhcp_vendor+0xbd>
lea    0x1(%rax),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rbx
jb     11ed <dhcp_vendor+0xbd>
add    %eax,%r15d
sub    %r14d,%r15d
mov    %r15d,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8* }
@.str = [6 x i8] c"%s-%s\00"
@.str.1 = [7 x i8] c"dhcpcd\00"
@.str.2 = [6 x i8] c"6.7.1\00"
@.str.3 = [15 x i8] c"%s-%s:%s-%s:%s\00"
define i32 @dhcp_vendor(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.utsname
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = call i64 @uname(%struct.utsname* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 %14, i32* %3
br label %67
15: ; preds = %2
%16 = load i8*, i8** %4
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i64, i64* %5
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 2
%24 = load i8*, i8** %23
%25 = call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %17, i64 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %22, i8* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %34, label %28
28: ; preds = %15
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = load i64, i64* %5
%33 = icmp ugt i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %28, %15
store i32 -1, i32* %3
br label %67
35: ; preds = %28
%36 = load i32, i32* %8
%37 = load i8*, i8** %7
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %7
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = load i64, i64* %5
%43 = sub i64 %42, %41
store i64 %43, i64* %5
%44 = load i8*, i8** %7
%45 = load i64, i64* %5
%46 = call i32 @if_machinearch(i8* %44, i64 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, -1
br i1 %48, label %55, label %49
49: ; preds = %35
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = load i64, i64* %5
%54 = icmp ugt i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %49, %35
store i32 -1, i32* %3
br label %67
56: ; preds = %49
%57 = load i32, i32* %8
%58 = load i8*, i8** %7
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %7
%61 = load i8*, i8** %7
%62 = load i8*, i8** %4
%63 = ptrtoint i8* %61 to i64
%64 = ptrtoint i8* %62 to i64
%65 = sub i64 %63, %64
%66 = trunc i64 %65 to i32
store i32 %66, i32* %3
br label %67
67: ; preds = %56, %55, %34, %11
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8* }
@.str = [6 x i8] c"%s-%s\00"
@.str.1 = [7 x i8] c"dhcpcd\00"
@.str.2 = [6 x i8] c"6.7.1\00"
@.str.3 = [15 x i8] c"%s-%s:%s-%s:%s\00"
define i32 @dhcp_vendor(i8* %0, i64 %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i64 @uname(%struct.utsname* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 2
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %13, i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %39, label %18
18: ; preds = %9
%19 = add nuw nsw i32 %16, 1
%20 = sext i32 %19 to i64
%21 = icmp ugt i64 %20, %1
br i1 %21, label %39, label %22
22: ; preds = %18
%23 = sext i32 %16 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = sub i64 %1, %23
%26 = tail call i32 @if_machinearch(i8* %24, i64 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %39, label %28
28: ; preds = %22
%29 = add nuw nsw i32 %26, 1
%30 = sext i32 %29 to i64
%31 = icmp ult i64 %25, %30
br i1 %31, label %39, label %32
32: ; preds = %28
%33 = sext i32 %26 to i64
%34 = getelementptr inbounds i8, i8* %24, i64 %33
%35 = ptrtoint i8* %34 to i64
%36 = ptrtoint i8* %0 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
br label %39
39: ; preds = %22, %28, %9, %18, %32, %7
%40 = phi i32 [ %8, %7 ], [ %38, %32 ], [ -1, %18 ], [ -1, %9 ], [ -1, %28 ], [ -1, %22 ]
ret i32 %40
}