#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 int, unsigned int,
                            unsigned int, unsigned int);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int get_serio_modalias(char *modalias, int modalias_len) {
  char *serio_type_env, *serio_proto_env;
  char *serio_id_env, *serio_extra_env;
  unsigned int serio_type, serio_proto;
  unsigned int serio_specifier, serio_version;
  serio_type_env = getenv("SERIO_TYPE");
  serio_proto_env = getenv("SERIO_PROTO");
  serio_id_env = getenv("SERIO_ID");
  serio_extra_env = getenv("SERIO_EXTRA");
  if (serio_type_env == NULL || serio_proto_env == NULL ||
      serio_id_env == NULL || serio_extra_env == NULL)
    return -1;
  serio_type = strtoul(serio_type_env, NULL, 16);
  serio_proto = strtoul(serio_proto_env, NULL, 16);
  serio_specifier = strtoul(serio_id_env, NULL, 16);
  serio_version = strtoul(serio_extra_env, NULL, 16);
  snprintf(modalias, modalias_len, "MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
           serio_type, serio_proto, serio_specifier, serio_version);
  return 0;
}


x86 assembly (clang, -O0):
<get_serio_modalias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
lea    0xeb1(%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_serio_modalias+0x7b>
cmpq   $0x0,-0x28(%rbp)
je     11ab <get_serio_modalias+0x7b>
cmpq   $0x0,-0x30(%rbp)
je     11ab <get_serio_modalias+0x7b>
cmpq   $0x0,-0x38(%rbp)
jne    11b7 <get_serio_modalias+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <get_serio_modalias+0x106>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x44(%rbp),%r9d
mov    -0x48(%rbp),%eax
lea    0xe05(%rip),%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_serio_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    0xeb0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xead(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xffffffff,%r12d
test   %r14,%r14
je     1200 <get_serio_modalias+0xd0>
test   %rbx,%rbx
je     1200 <get_serio_modalias+0xd0>
test   %rbp,%rbp
je     1200 <get_serio_modalias+0xd0>
mov    %rax,%r13
test   %rax,%rax
je     1200 <get_serio_modalias+0xd0>
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,%ebp
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,(%rsp)
lea    0xe41(%rip),%rdx
mov    %r15,%rdi
mov    0x14(%rsp),%esi
mov    %r14d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
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 = [11 x i8] c"SERIO_TYPE\00"
@.str.1 = [12 x i8] c"SERIO_PROTO\00"
@.str.2 = [9 x i8] c"SERIO_ID\00"
@.str.3 = [12 x i8] c"SERIO_EXTRA\00"
@.str.4 = [40 x i8] c"MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X\00"
define i32 @get_serio_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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%14 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %7
%16 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %8
%17 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 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 i32 @strtoul(i8* %31, i32* null, i32 16)
store i32 %32, i32* %10
%33 = load i8*, i8** %7
%34 = call i32 @strtoul(i8* %33, i32* null, i32 16)
store i32 %34, i32* %11
%35 = load i8*, i8** %8
%36 = call i32 @strtoul(i8* %35, i32* null, i32 16)
store i32 %36, i32* %12
%37 = load i8*, i8** %9
%38 = call i32 @strtoul(i8* %37, i32* null, i32 16)
store i32 %38, i32* %13
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = load i32, i32* %13
%45 = call i32 @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42, i32 %43, i32 %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 = [11 x i8] c"SERIO_TYPE\00"
@.str.1 = [12 x i8] c"SERIO_PROTO\00"
@.str.2 = [9 x i8] c"SERIO_ID\00"
@.str.3 = [12 x i8] c"SERIO_EXTRA\00"
@.str.4 = [40 x i8] c"MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X\00"
define i32 @get_serio_modalias(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 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 i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%16 = tail call i32 @strtoul(i8* nocapture %4, i32* null, i32 16)
%17 = tail call i32 @strtoul(i8* nocapture %5, i32* null, i32 16)
%18 = tail call i32 @strtoul(i8* nocapture %6, i32* null, i32 16)
%19 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %15, i32 %16, i32 %17, i32 %18)
br label %20
20: ; preds = %2, %14
%21 = phi i32 [ 0, %14 ], [ -1, %2 ]
ret i32 %21
}