#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*/ skipWhite(char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char *);
char *strstr(char *, char *);
int gwGetTimezone(char *tz, char *zn) {
  FILE *fp;
  char line[80];
  char *s;
  tz[0] = '\0';
  zn[0] = '\0';
  if ((fp = fopen("/etc/config/system", "r")) != NULL) {
    while (fgets(line, 80, fp) != NULL) {
      int len = strlen(line);
      if (len > 1) {
        if (line[len - 1] == '\n')
          line[len - 1] = '\0';
        len--;
      }
      if ((s = strstr(line, "timezone")) != NULL) {
        strcpy(tz, skipWhite(s + 8));
      }
      if ((s = strstr(line, "zonename")) != NULL) {
        strcpy(zn, skipWhite(s + 8));
      }
    }
    fclose(fp);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gwGetTimezone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe68(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12b7 <gwGetTimezone+0x147>
jmp    11b7 <gwGetTimezone+0x47>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12a2 <gwGetTimezone+0x132>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x1,-0x7c(%rbp)
jle    1215 <gwGetTimezone+0xa5>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    120c <gwGetTimezone+0x9c>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     1259 <gwGetTimezone+0xe9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rdi
add    $0x8,%rdi
call   1070 <skipWhite@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     129d <gwGetTimezone+0x12d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x78(%rbp),%rdi
add    $0x8,%rdi
call   1070 <skipWhite@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
jmp    11b7 <gwGetTimezone+0x47>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <gwGetTimezone+0x14e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gwGetTimezone>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,(%rdi)
movb   $0x0,(%rsi)
lea    0xe6f(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     126c <gwGetTimezone+0xfc>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     125d <gwGetTimezone+0xed>
mov    %rsp,%rbx
lea    0xe49(%rip),%r13
lea    0xe4b(%rip),%rbp
jmp    11f5 <gwGetTimezone+0x85>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     125d <gwGetTimezone+0xed>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     120f <gwGetTimezone+0x9f>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    120f <gwGetTimezone+0x9f>
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1235 <gwGetTimezone+0xc5>
add    $0x8,%rax
mov    %rax,%rdi
call   1070 <skipWhite@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11e0 <gwGetTimezone+0x70>
add    $0x8,%rax
mov    %rax,%rdi
call   1070 <skipWhite@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
jmp    11e0 <gwGetTimezone+0x70>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    126e <gwGetTimezone+0xfe>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/etc/config/system\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"timezone\00"
@.str.3 = [9 x i8] c"zonename\00"
define i32 @gwGetTimezone(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [80 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %67
16: ; preds = %2
br label %17
17: ; preds = %63, %16
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32* @fgets(i8* %18, i32 80, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %64
22: ; preds = %17
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %43
27: ; preds = %22
%28 = load i32, i32* %9
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %40
35: ; preds = %27
%36 = load i32, i32* %9
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35, %27
%41 = load i32, i32* %9
%42 = add nsw i32 %41, -1
store i32 %42, i32* %9
br label %43
43: ; preds = %40, %22
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%45 = call i8* @strstr(i8* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %45, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i8*, i8** %4
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i64 8
%51 = call i32 @skipWhite(i8* %50)
%52 = call i32 @strcpy(i8* %48, i32 %51)
br label %53
53: ; preds = %47, %43
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%55 = call i8* @strstr(i8* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %55, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = load i8*, i8** %5
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i64 8
%61 = call i32 @skipWhite(i8* %60)
%62 = call i32 @strcpy(i8* %58, i32 %61)
br label %63
63: ; preds = %57, %53
br label %17
64: ; preds = %17
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
store i32 1, i32* %3
br label %68
67: ; preds = %2
store i32 0, i32* %3
br label %68
68: ; preds = %67, %64
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [19 x i8] c"/etc/config/system\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"timezone\00"
@.str.3 = [9 x i8] c"zonename\00"
define i32 @gwGetTimezone(i8* %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
store i8 0, i8* %0
store i8 0, i8* %1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %39, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 80, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %37, label %10
10: ; preds = %7, %34
%11 = call i32 @strlen(i8* %4)
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = add nsw i32 %11, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %13
store i8 0, i8* %16
br label %20
20: ; preds = %13, %19, %10
%21 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 8
%25 = call i32 @skipWhite(i8* %24)
%26 = call i32 @strcpy(i8* %0, i32 %25)
br label %27
27: ; preds = %23, %20
%28 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = getelementptr inbounds i8, i8* %28, i64 8
%32 = call i32 @skipWhite(i8* %31)
%33 = call i32 @strcpy(i8* %1, i32 %32)
br label %34
34: ; preds = %30, %27
%35 = call i32* @fgets(i8* %4, i32 80, i32* %5)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %10
37: ; preds = %34, %7
%38 = call i32 @fclose(i32* %5)
br label %39
39: ; preds = %2, %37
%40 = phi i32 [ 1, %37 ], [ 0, %2 ]
ret i32 %40
}