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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ trimRight(char *);
void vIfTZisLocal(char *psz) {
  char szLocal[32];
  if (strcasecmp(psz, "local") == 0) {
    FILE *fp = fopen("/etc/timezone", "r");
    if (fp != NULL) {
      fread(szLocal, 1, sizeof(szLocal), fp);
      fclose(fp);
      strcpy(psz, szLocal);
    }
  }
  trimRight(psz);
}


x86 assembly (clang, -O0):
<vIfTZisLocal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11da <vIfTZisLocal+0x7a>
lea    0xe79(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11d5 <vIfTZisLocal+0x75>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1050 <fread@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11da <vIfTZisLocal+0x7a>
mov    -0x8(%rbp),%rdi
call   1070 <trimRight@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vIfTZisLocal>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0xe8d(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    11c3 <vIfTZisLocal+0x63>
lea    0xe82(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c3 <vIfTZisLocal+0x63>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <trimRight@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"local\00"
@.str.1 = [14 x i8] c"/etc/timezone\00"
@.str.2 = [2 x i8] c"r\00"
define void @vIfTZisLocal(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32 @fread(i8* %13, i32 1, i32 32, i32* %14)
%16 = load i32*, i32** %4
%17 = call i32 @fclose(i32* %16)
%18 = load i8*, i8** %2
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%20 = call i32 @strcpy(i8* %18, i8* %19)
br label %21
21: ; preds = %12, %8
br label %22
22: ; preds = %21, %1
%23 = load i8*, i8** %2
%24 = call i32 @trimRight(i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"local\00"
@.str.1 = [14 x i8] c"/etc/timezone\00"
@.str.2 = [2 x i8] c"r\00"
define void @vIfTZisLocal(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strcasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = call i32 @fread(i8* %3, i32 1, i32 32, i32* %7)
%11 = tail call i32 @fclose(i32* %7)
%12 = call i32 @strcpy(i8* %0, i8* %3)
br label %13
13: ; preds = %6, %9, %1
%14 = call i32 @trimRight(i8* %0)
ret void
}