#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 *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long, unsigned long,
                            unsigned long, unsigned long);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int get_ieee1394_modalias(char *modalias, int modalias_len) {
  char *vendor_env, *model_env;
  char *specifier_env, *version_env;
  unsigned long vendor, model;
  unsigned long specifier, version;
  vendor_env = getenv("VENDOR_ID");
  model_env = getenv("MODEL_ID");
  specifier_env = getenv("SPECIFIER_ID");
  version_env = getenv("VERSION");
  if (vendor_env == NULL || model_env == NULL || specifier_env == NULL ||
      version_env == NULL)
    return -1;
  vendor = strtoul(vendor_env, NULL, 16);
  model = strtoul(model_env, NULL, 16);
  specifier = strtoul(specifier_env, NULL, 16);
  version = strtoul(version_env, NULL, 16);
  snprintf(modalias, modalias_len,
           "MODALIAS=ieee1394:ven%08lXmo%08lXsp%08lXver%08lX", vendor, model,
           specifier, version);
  return 0;
}


x86 assembly (clang, -O0):
<get_ieee1394_modalias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
lea    0xead(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ab <get_ieee1394_modalias+0x7b>
cmpq   $0x0,-0x28(%rbp)
je     11ab <get_ieee1394_modalias+0x7b>
cmpq   $0x0,-0x30(%rbp)
je     11ab <get_ieee1394_modalias+0x7b>
cmpq   $0x0,-0x38(%rbp)
jne    11b7 <get_ieee1394_modalias+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <get_ieee1394_modalias+0x10d>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9
mov    -0x58(%rbp),%rax
lea    0xdfb(%rip),%rdx
mov    %rax,(%rsp)
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ieee1394_modalias>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0x14(%rsp)
mov    %rdi,%r15
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xffffffff,%r12d
test   %r14,%r14
je     1203 <get_ieee1394_modalias+0xd3>
test   %rbx,%rbx
je     1203 <get_ieee1394_modalias+0xd3>
test   %rbp,%rbp
je     1203 <get_ieee1394_modalias+0xd3>
mov    %rax,%r13
test   %rax,%rax
je     1203 <get_ieee1394_modalias+0xd3>
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbp
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,(%rsp)
lea    0xe3a(%rip),%rdx
mov    %r15,%rdi
mov    0x14(%rsp),%esi
mov    %r14,%rcx
mov    %rbx,%r8
mov    %rbp,%r9
call   1040 <snprintf@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"VENDOR_ID\00"
@.str.1 = [9 x i8] c"MODEL_ID\00"
@.str.2 = [13 x i8] c"SPECIFIER_ID\00"
@.str.3 = [8 x i8] c"VERSION\00"
@.str.4 = [49 x i8] c"MODALIAS=ieee1394:ven%08lXmo%08lXsp%08lXver%08lX\00"
define i32 @get_ieee1394_modalias(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%14 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %7
%16 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %8
%17 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %17, i8** %9
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %29, label %20
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i8*, i8** %9
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %20, %2
store i32 -1, i32* %3
br label %46
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = call i64 @strtoul(i8* %31, i32* null, i32 16)
store i64 %32, i64* %10
%33 = load i8*, i8** %7
%34 = call i64 @strtoul(i8* %33, i32* null, i32 16)
store i64 %34, i64* %11
%35 = load i8*, i8** %8
%36 = call i64 @strtoul(i8* %35, i32* null, i32 16)
store i64 %36, i64* %12
%37 = load i8*, i8** %9
%38 = call i64 @strtoul(i8* %37, i32* null, i32 16)
store i64 %38, i64* %13
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = load i64, i64* %10
%42 = load i64, i64* %11
%43 = load i64, i64* %12
%44 = load i64, i64* %13
%45 = call i32 @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i64 %41, i64 %42, i64 %43, i64 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %30, %29
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [10 x i8] c"VENDOR_ID\00"
@.str.1 = [9 x i8] c"MODEL_ID\00"
@.str.2 = [13 x i8] c"SPECIFIER_ID\00"
@.str.3 = [8 x i8] c"VERSION\00"
@.str.4 = [49 x i8] c"MODALIAS=ieee1394:ven%08lXmo%08lXsp%08lXver%08lX\00"
define i32 @get_ieee1394_modalias(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i8* %3, null
%8 = icmp eq i8* %4, null
%9 = or i1 %7, %8
%10 = icmp eq i8* %5, null
%11 = or i1 %9, %10
%12 = icmp eq i8* %6, null
%13 = or i1 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = tail call i64 @strtoul(i8* nocapture %3, i32* null, i32 16)
%16 = tail call i64 @strtoul(i8* nocapture %4, i32* null, i32 16)
%17 = tail call i64 @strtoul(i8* nocapture %5, i32* null, i32 16)
%18 = tail call i64 @strtoul(i8* nocapture %6, i32* null, i32 16)
%19 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i64 %15, i64 %16, i64 %17, i64 %18)
br label %20
20: ; preds = %2, %14
%21 = phi i32 [ 0, %14 ], [ -1, %2 ]
ret i32 %21
}