#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*/ tz;
typedef int time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct tm *localtime(int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
int main() {
  time_t now;
  struct tm *lt;
  char tz[10];
  now = time(NULL);
  if (now == -1) {
    perror("Failed to read time");
    exit(1);
  }
  lt = localtime(&now);
  if (lt == 0) {
    perror("Failed to get localtime");
    exit(1);
  }
  if (strftime(tz, sizeof(tz), "%z", lt) == 0) {
    perror("Failed to get timezone");
    exit(1);
  }
  printf("%s\n", tz);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    119b <main+0x3b>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <main+0x69>
lea    0xe5a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xa,%esi
lea    0xe4f(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    1202 <main+0xa2>
lea    0xe3c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x1a(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
je     11b9 <main+0x59>
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11c2 <main+0x62>
lea    0xea2(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
je     11cb <main+0x6b>
lea    0xe9e(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe40(%rip),%rdi
jmp    11d2 <main+0x72>
lea    0xe4b(%rip),%rdi
jmp    11d2 <main+0x72>
lea    0xe5d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [20 x i8] c"Failed to read time\00"
@.str.1 = [24 x i8] c"Failed to get localtime\00"
@.str.2 = [3 x i8] c"%z\00"
@.str.3 = [23 x i8] c"Failed to get timezone\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca [10 x i8]
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %12, %struct.tm** %3
%13 = load %struct.tm*, %struct.tm** %3
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%20 = load %struct.tm*, %struct.tm** %3
%21 = call i64 @strftime(i8* %19, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [20 x i8] c"Failed to read time\00"
@.str.1 = [24 x i8] c"Failed to get localtime\00"
@.str.2 = [3 x i8] c"%z\00"
@.str.3 = [23 x i8] c"Failed to get timezone\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call %struct.tm* @localtime(i32* %1)
%12 = icmp eq %struct.tm* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = call i64 @strftime(i8* %4, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret i32 0
}