#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ setenv(char *, char *, int);
char *strchr(char *, char);
int readuevent(const char *file) {
  FILE *fp;
  int status = 0;
  char buf[BUFSIZ];
  char *p, *name, *value;
  if (!(fp = fopen(file, "r")))
    return -1;
  while (!feof(fp)) {
    fgets(buf, sizeof(buf) - 1, fp);
    if (ferror(fp)) {
      status = -2;
      break;
    }
    if ((p = strchr(buf, '\n')))
      *p = '\0';
    if (!(p = strchr(buf, '=')))
      continue;
    *p = '\0';
    p++;
    name = buf;
    value = p;
    setenv(name, value, 1);
  }
  fclose(fp);
  return status;
}


x86 assembly (clang, -O0):
<readuevent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e4 <readuevent+0x74>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    12d1 <readuevent+0x161>
jmp    11e9 <readuevent+0x79>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1207 <readuevent+0x97>
jmp    12bb <readuevent+0x14b>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1070 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     123d <readuevent+0xcd>
movl   $0xfffffffe,-0x1c(%rbp)
jmp    12bb <readuevent+0x14b>
mov    -0x58(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1260 <readuevent+0xf0>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1281 <readuevent+0x111>
jmp    11e9 <readuevent+0x79>
mov    -0x58(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rcx)
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11e9 <readuevent+0x79>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readuevent>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e5e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1237 <readuevent+0xc7>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <feof@plt>
xor    %r12d,%r12d
test   %eax,%eax
jne    1245 <readuevent+0xd5>
add    $0xffffffff,%r14d
jmp    11dc <readuevent+0x6c>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1245 <readuevent+0xd5>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    123f <readuevent+0xcf>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     120c <readuevent+0x9c>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11d0 <readuevent+0x60>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11d0 <readuevent+0x60>
mov    $0xffffffff,%r12d
jmp    124d <readuevent+0xdd>
mov    $0xfffffffe,%r12d
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @readuevent(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %11
br label %56
20: ; preds = %1
br label %21
21: ; preds = %44, %43, %20
%22 = load i32*, i32** %4
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %52
26: ; preds = %21
%27 = sub i64 %13, 1
%28 = trunc i64 %27 to i32
%29 = load i32*, i32** %4
%30 = call i32 @fgets(i8* %15, i32 %28, i32* %29)
%31 = load i32*, i32** %4
%32 = call i64 @ferror(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %26
store i32 -2, i32* %5
br label %52
35: ; preds = %26
%36 = call i8* @strchr(i8* %15, i8 signext 10)
store i8* %36, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i8*, i8** %8
store i8 0, i8* %39
br label %40
40: ; preds = %38, %35
%41 = call i8* @strchr(i8* %15, i8 signext 61)
store i8* %41, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %40
br label %21
44: ; preds = %40
%45 = load i8*, i8** %8
store i8 0, i8* %45
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %8
store i8* %15, i8** %9
%48 = load i8*, i8** %8
store i8* %48, i8** %10
%49 = load i8*, i8** %9
%50 = load i8*, i8** %10
%51 = call i32 @setenv(i8* %49, i8* %50, i32 1)
br label %21
52: ; preds = %34, %21
%53 = load i32*, i32** %4
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* %5
store i32 %55, i32* %2
store i32 1, i32* %11
br label %56
56: ; preds = %52, %19
%57 = load i8*, i8** %6
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @readuevent(i8* nocapture %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %31, label %7
7: ; preds = %1
%8 = add i32 %2, -1
%9 = call i32 @feof(i32* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %7, %25
%12 = call i32 @fgets(i8* %4, i32 %8, i32* %5)
%13 = call i64 @ferror(i32* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = call i8* @strchr(i8* %4, i8 signext 10)
%17 = icmp eq i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15
store i8 0, i8* %16
br label %19
19: ; preds = %18, %15
%20 = call i8* @strchr(i8* %4, i8 signext 61)
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %19
store i8 0, i8* %20
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = call i32 @setenv(i8* %4, i8* %23, i32 1)
br label %25
25: ; preds = %22, %19
%26 = call i32 @feof(i32* %5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %11, label %28
28: ; preds = %25, %11, %7
%29 = phi i32 [ 0, %7 ], [ -2, %11 ], [ 0, %25 ]
%30 = call i32 @fclose(i32* %5)
br label %31
31: ; preds = %1, %28
%32 = phi i32 [ %29, %28 ], [ -1, %1 ]
ret i32 %32
}