#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 */
struct rtc_time {
  int dummy;
};

/* Variables and functions */
int do_read_time(int, struct rtc_time *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ print_tm(struct rtc_time *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int test_read_time(int fd) {
  int ret;
  struct rtc_time time;
  printf("==== read time ====\n");
  ret = do_read_time(fd, &time);
  if (ret) {
    printf("get time failed: %s\n", strerror(errno));
    return ret;
  }
  printf("\tget time OK.\n");
  print_tm(&time);
  return 0;
}


x86 assembly (clang, -O0):
<test_read_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <do_read_time@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     119c <test_read_time+0x5c>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <test_read_time+0x7a>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1040 <print_tm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_time>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1060 <do_read_time@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1196 <test_read_time+0x46>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ac <test_read_time+0x5c>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1050 <print_tm@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rtc_time = type { i32 }
@.str = [21 x i8] c"==== read time ====\0A\00"
@.str.1 = [21 x i8] c"get time failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [15 x i8] c"\09get time OK.\0A\00"
define i32 @test_read_time(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.rtc_time
store i32 %0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %3
%8 = call i32 @do_read_time(i32 %7, %struct.rtc_time* %5)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %19
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @print_tm(%struct.rtc_time* %5)
store i32 0, i32* %2
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.rtc_time = type { i32 }
@.str.1 = [21 x i8] c"get time failed: %s\0A\00"
@errno = global i32 0
@str = [20 x i8] c"==== read time ====\00"
@str.3 = [14 x i8] c"\09get time OK.\00"
define i32 @test_read_time(i32 %0) {
%2 = alloca %struct.rtc_time
%3 = bitcast %struct.rtc_time* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%5 = call i32 @do_read_time(i32 %0, %struct.rtc_time* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %14
11: ; preds = %1
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
%13 = call i32 @print_tm(%struct.rtc_time* %2)
br label %14
14: ; preds = %11, %7
ret i32 %5
}