#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_kernel_seqnum();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *xmalloc(int);
char *xrealloc(char *, unsigned long);
char *get_uevent_string(char **environ, unsigned long *uevent_string_len) {
  char *uevent_string;
  char *tmp;
  unsigned long offset;
  *uevent_string_len = 4;
  offset = *uevent_string_len - 1;
  uevent_string = xmalloc(*uevent_string_len);
  strcpy(uevent_string, "add");
  uevent_string[offset] = '@';
  offset++;
  for (; *environ != NULL; environ++) {
    *uevent_string_len += strlen(*environ) + 1;
    uevent_string = xrealloc(uevent_string, *uevent_string_len);
    strcpy(&uevent_string[offset], *environ);
    offset = *uevent_string_len;
  }
  tmp = xmalloc(72);
  memset(tmp, 0, 72);
  snprintf(tmp, 72, "SEQNUM=%llu", get_kernel_seqnum());
  *uevent_string_len += strlen(tmp) + 1;
  uevent_string = xrealloc(uevent_string, *uevent_string_len);
  strcpy(&uevent_string[offset], tmp);
  offset = *uevent_string_len;
  free(tmp);
  return uevent_string;
}


x86 assembly (clang, -O0):
<get_uevent_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x4,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x40,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1253 <get_uevent_string+0xd3>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1070 <xrealloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <get_uevent_string+0x64>
mov    $0x48,%edi
call   1090 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   10a0 <get_kernel_seqnum@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%ecx
mov    $0x48,%esi
lea    0xd72(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1070 <xrealloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uevent_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
movq   $0x4,(%rsi)
mov    $0x4,%edi
call   1090 <xmalloc@plt>
mov    %rax,%r15
lea    0xe56(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
movb   $0x40,0x3(%r15)
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     120f <get_uevent_string+0x8f>
mov    (%r14),%r12
add    $0x8,%r13
mov    $0x4,%ebx
nopl   0x0(%rax)
call   1050 <strlen@plt>
lea    (%rax,%r12,1),%rsi
add    $0x1,%rsi
mov    %rsi,(%r14)
mov    %r15,%rdi
call   1070 <xrealloc@plt>
mov    %rax,%r15
add    %rax,%rbx
mov    -0x8(%r13),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    (%r14),%r12
mov    0x0(%r13),%rdi
add    $0x8,%r13
mov    %r12,%rbx
test   %rdi,%rdi
jne    11d0 <get_uevent_string+0x50>
jmp    1215 <get_uevent_string+0x95>
mov    $0x4,%r12d
mov    $0x48,%edi
call   1090 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1080 <memset@plt>
xor    %eax,%eax
call   10a0 <get_kernel_seqnum@plt>
lea    0xdc5(%rip),%rdx
mov    %rbx,%rdi
mov    $0x48,%esi
mov    %eax,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    (%r14),%rcx
lea    (%rax,%rcx,1),%rsi
add    $0x1,%rsi
mov    %rsi,(%r14)
mov    %r15,%rdi
call   1070 <xrealloc@plt>
mov    %rax,%r14
add    %rax,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"add\00"
@.str.1 = [12 x i8] c"SEQNUM=%llu\00"
define i8* @get_uevent_string(i8** %0, i64* %1) {
%3 = alloca i8**
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %3
store i64* %1, i64** %4
%8 = load i64*, i64** %4
store i64 4, i64* %8
%9 = load i64*, i64** %4
%10 = load i64, i64* %9
%11 = sub i64 %10, 1
store i64 %11, i64* %7
%12 = load i64*, i64** %4
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = call i8* @xmalloc(i32 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %5
%19 = load i64, i64* %7
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8 64, i8* %20
%21 = load i64, i64* %7
%22 = add i64 %21, 1
store i64 %22, i64* %7
br label %23
23: ; preds = %47, %2
%24 = load i8**, i8*** %3
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %50
27: ; preds = %23
%28 = load i8**, i8*** %3
%29 = load i8*, i8** %28
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = load i64*, i64** %4
%33 = load i64, i64* %32
%34 = add i64 %33, %31
store i64 %34, i64* %32
%35 = load i8*, i8** %5
%36 = load i64*, i64** %4
%37 = load i64, i64* %36
%38 = call i8* @xrealloc(i8* %35, i64 %37)
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = load i64, i64* %7
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8**, i8*** %3
%43 = load i8*, i8** %42
%44 = call i32 @strcpy(i8* %41, i8* %43)
%45 = load i64*, i64** %4
%46 = load i64, i64* %45
store i64 %46, i64* %7
br label %47
47: ; preds = %27
%48 = load i8**, i8*** %3
%49 = getelementptr inbounds i8*, i8** %48, i32 1
store i8** %49, i8*** %3
br label %23
50: ; preds = %23
%51 = call i8* @xmalloc(i32 72)
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = call i32 @memset(i8* %52, i32 0, i32 72)
%54 = load i8*, i8** %6
%55 = call i32 (...) @get_kernel_seqnum()
%56 = call i32 @snprintf(i8* %54, i32 72, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i8*, i8** %6
%58 = call i64 @strlen(i8* %57)
%59 = add nsw i64 %58, 1
%60 = load i64*, i64** %4
%61 = load i64, i64* %60
%62 = add i64 %61, %59
store i64 %62, i64* %60
%63 = load i8*, i8** %5
%64 = load i64*, i64** %4
%65 = load i64, i64* %64
%66 = call i8* @xrealloc(i8* %63, i64 %65)
store i8* %66, i8** %5
%67 = load i8*, i8** %5
%68 = load i64, i64* %7
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = load i8*, i8** %6
%71 = call i32 @strcpy(i8* %69, i8* %70)
%72 = load i64*, i64** %4
%73 = load i64, i64* %72
store i64 %73, i64* %7
%74 = load i8*, i8** %6
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %5
ret i8* %76
}

LLVM IR (-O2):
@.str = [4 x i8] c"add\00"
@.str.1 = [12 x i8] c"SEQNUM=%llu\00"
define i8* @get_uevent_string(i8** nocapture %0, i64* nocapture %1) {
store i64 4, i64* %1
%3 = tail call i8* @xmalloc(i32 4)
%4 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %3, i64 3
store i8 64, i8* %5
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = load i64, i64* %1
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %23, %10 ], [ %9, %8 ]
%12 = phi i8* [ %25, %10 ], [ %6, %8 ]
%13 = phi i64 [ %23, %10 ], [ 4, %8 ]
%14 = phi i8** [ %24, %10 ], [ %0, %8 ]
%15 = phi i8* [ %19, %10 ], [ %3, %8 ]
%16 = tail call i64 @strlen(i8* %12)
%17 = add nsw i64 %16, 1
%18 = add i64 %17, %11
store i64 %18, i64* %1
%19 = tail call i8* @xrealloc(i8* %15, i64 %18)
%20 = getelementptr inbounds i8, i8* %19, i64 %13
%21 = load i8*, i8** %14
%22 = tail call i32 @strcpy(i8* %20, i8* %21)
%23 = load i64, i64* %1
%24 = getelementptr inbounds i8*, i8** %14, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %10
27: ; preds = %10, %2
%28 = phi i8* [ %3, %2 ], [ %19, %10 ]
%29 = phi i64 [ 4, %2 ], [ %23, %10 ]
%30 = tail call i8* @xmalloc(i32 72)
%31 = tail call i32 @memset(i8* %30, i32 0, i32 72)
%32 = tail call i32 (...) @get_kernel_seqnum()
%33 = tail call i32 @snprintf(i8* %30, i32 72, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = tail call i64 @strlen(i8* dereferenceable(1) %30)
%35 = add nsw i64 %34, 1
%36 = load i64, i64* %1
%37 = add i64 %35, %36
store i64 %37, i64* %1
%38 = tail call i8* @xrealloc(i8* %28, i64 %37)
%39 = getelementptr inbounds i8, i8* %38, i64 %29
%40 = tail call i32 @strcpy(i8* %39, i8* %30)
%41 = tail call i32 @free(i8* %30)
ret i8* %38
}