#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*/ O_RDONLY;
char *index(char *, char);
int open(char *, int /*<<< orphan*/);
size_t read(int, char *, size_t);
void get_timezone(char *buf, size_t max) {
  int tzf = open("/etc/timezone", O_RDONLY);
  size_t count = read(tzf, buf, max - 1);
  buf[count + 1] = '\0';
  char *nl = index(buf, '\n');
  if (nl != NULL)
    *nl = '\0';
}


x86 assembly (clang, -O0):
<get_timezone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <read@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1030 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a1 <get_timezone+0x71>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timezone>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1050 <open@plt>
add    $0xffffffffffffffff,%rbx
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <read@plt>
movb   $0x0,0x1(%rax,%r14,1)
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <index@plt>
test   %rax,%rax
je     117b <get_timezone+0x4b>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/etc/timezone\00"
@O_RDONLY = global i32 0
define void @get_timezone(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = sub i64 %12, 1
%14 = call i64 @read(i32 %10, i8* %11, i64 %13)
store i64 %14, i64* %6
%15 = load i8*, i8** %3
%16 = load i64, i64* %6
%17 = add i64 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = call i8* @index(i8* %19, i8 signext 10)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = load i8*, i8** %7
store i8 0, i8* %24
br label %25
25: ; preds = %23, %2
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/etc/timezone\00"
@O_RDONLY = global i32 0
define void @get_timezone(i8* %0, i64 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = add i64 %1, -1
%6 = tail call i64 @read(i32 %4, i8* %0, i64 %5)
%7 = add i64 %6, 1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
%9 = tail call i8* @index(i8* %0, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8 0, i8* %9
br label %12
12: ; preds = %11, %2
ret void
}