#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ log_environment();
int /*<<< orphan*/ lprintf(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok(char *, char *);
void set_i18n(void) {
  FILE *f;
  lprintf("entering set_i18n");
  f = fopen("/etc/sysconfig/i18n", "r");
  if (f) {
    char buf[256];
    char *key;
    char *val;
    while (fgets(buf, 256, f) != NULL) {
      char *c;
      c = strchr(buf, '\n');
      if (c)
        *c = 0;
      if (buf[0] == '#')
        continue;
      key = strtok(buf, "=");
      if (!key)
        continue;
      val = strtok(NULL, "=\"");
      if (!val)
        continue;
      if (!strcmp(key, "LANG")) {
        setenv(key, val, 1);
      }
      if (!strcmp(key, "SYSFONT"))
        setenv(key, val, 1);
    }
    fclose(f);
  }
  log_environment();
}


x86 assembly (clang, -O0):
<set_i18n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
lea    0xe5e(%rip),%rdi
call   10b0 <lprintf@plt>
lea    0xe64(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12ff <set_i18n+0x16f>
jmp    11ce <set_i18n+0x3e>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12f6 <set_i18n+0x166>
lea    -0x110(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     121d <set_i18n+0x8d>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
movsbl -0x110(%rbp),%eax
cmp    $0x23,%eax
jne    1232 <set_i18n+0xa2>
jmp    11ce <set_i18n+0x3e>
lea    -0x110(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    125f <set_i18n+0xcf>
jmp    11ce <set_i18n+0x3e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc0(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    1289 <set_i18n+0xf9>
jmp    11ce <set_i18n+0x3e>
mov    -0x118(%rbp),%rdi
lea    0xd96(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12bd <set_i18n+0x12d>
mov    -0x118(%rbp),%rdi
mov    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x118(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12f1 <set_i18n+0x161>
mov    -0x118(%rbp),%rdi
mov    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
jmp    11ce <set_i18n+0x3e>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1080 <log_environment@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_i18n>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe58(%rip),%rdi
call   10b0 <lprintf@plt>
lea    0xe5e(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b0 <set_i18n+0x120>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12a8 <set_i18n+0x118>
mov    %rsp,%rbx
lea    0xe39(%rip),%r15
lea    0xe34(%rip),%r12
jmp    1219 <set_i18n+0x89>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12a8 <set_i18n+0x118>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     122e <set_i18n+0x9e>
movb   $0x0,(%rax)
cmpb   $0x23,(%rsp)
je     1200 <set_i18n+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1200 <set_i18n+0x70>
mov    %rax,%r13
xor    %edi,%edi
mov    %r12,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1200 <set_i18n+0x70>
mov    %rax,%rbp
mov    %r13,%rdi
lea    0xdca(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    127c <set_i18n+0xec>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %r13,%rdi
lea    0xdac(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    1200 <set_i18n+0x70>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
jmp    1200 <set_i18n+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1080 <log_environment@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"entering set_i18n\00"
@.str.1 = [20 x i8] c"/etc/sysconfig/i18n\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [3 x i8] c"=\22\00"
@.str.5 = [5 x i8] c"LANG\00"
@.str.6 = [8 x i8] c"SYSFONT\00"
define void @set_i18n() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i32 @lprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %1
%8 = load i32*, i32** %1
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %60
10: ; preds = %0
br label %11
11: ; preds = %56, %39, %34, %28, %10
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i32* @fgets(i8* %12, i32 256, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %57
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %5
store i8 0, i8* %22
br label %23
23: ; preds = %21, %16
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 35
br i1 %27, label %28, label %29
28: ; preds = %23
br label %11
29: ; preds = %23
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %31, i8** %3
%32 = load i8*, i8** %3
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %29
br label %11
35: ; preds = %29
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %36, i8** %4
%37 = load i8*, i8** %4
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %35
br label %11
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = load i8*, i8** %4
%47 = call i32 @setenv(i8* %45, i8* %46, i32 1)
br label %48
48: ; preds = %44, %40
%49 = load i8*, i8** %3
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %48
%53 = load i8*, i8** %3
%54 = load i8*, i8** %4
%55 = call i32 @setenv(i8* %53, i8* %54, i32 1)
br label %56
56: ; preds = %52, %48
br label %11
57: ; preds = %11
%58 = load i32*, i32** %1
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %57, %0
%61 = call i32 (...) @log_environment()
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"entering set_i18n\00"
@.str.1 = [20 x i8] c"/etc/sysconfig/i18n\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [3 x i8] c"=\22\00"
@.str.5 = [5 x i8] c"LANG\00"
@.str.6 = [8 x i8] c"SYSFONT\00"
define void @set_i18n() {
%1 = alloca [256 x i8]
%2 = tail call i32 @lprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %37, label %5
5: ; preds = %0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = call i32* @fgets(i8* %6, i32 256, i32* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %5, %32
%10 = call i8* @strchr(i8* %6, i8 signext 10)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8 0, i8* %10
br label %13
13: ; preds = %12, %9
%14 = load i8, i8* %6
%15 = icmp eq i8 %14, 35
br i1 %15, label %32, label %16
16: ; preds = %13
%17 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %32, label %22
22: ; preds = %19
%23 = call i32 @strcmp(i8* %17, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @setenv(i8* %17, i8* %20, i32 1)
br label %27
27: ; preds = %25, %22
%28 = call i32 @strcmp(i8* %17, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @setenv(i8* %17, i8* %20, i32 1)
br label %32
32: ; preds = %27, %30, %19, %16, %13
%33 = call i32* @fgets(i8* %6, i32 256, i32* %3)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %9
35: ; preds = %32, %5
%36 = call i32 @fclose(i32* %3)
br label %37
37: ; preds = %35, %0
%38 = call i32 (...) @log_environment()
ret void
}