#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 tm {
  int dummy;
};
struct timespec {
  int tv_sec;
};
typedef int /*<<< orphan*/ pthread_mutex_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ PTHREAD_MUTEX_INITIALIZER;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct tm *localtime(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_mutex_lock(int /*<<< orphan*/ *);
int pthread_mutex_timedlock(int /*<<< orphan*/ *, struct timespec *);
char *strerror(int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int main(void) {
  printf("hello world!");
  int err;
  struct timespec tout;
  struct tm *tmp;
  char buf[64];
  pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_lock(&lock);
  printf("mutex is locked\n");
  clock_gettime(CLOCK_REALTIME, &tout);
  tmp = localtime(&tout.tv_sec);
  strftime(buf, sizeof(buf), "%r", tmp);
  printf("current time is %s\n", buf);
  tout.tv_sec += 10;
  err = pthread_mutex_timedlock(&lock, &tout);
  clock_gettime(CLOCK_REALTIME, &tout);
  tmp = localtime(&tout.tv_sec);
  strftime(buf, sizeof(buf), "%r", tmp);
  printf("the time is now %s\n", buf);
  if (err == 0)
    printf("mutex locked again!\n");
  else
    printf("can't locked mutex again: %s\n", strerror(err));
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    -0x64(%rbp),%rdi
call   10a0 <pthread_mutex_lock@plt>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <clock_gettime@plt>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe2b(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x60(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
lea    -0x64(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <pthread_mutex_timedlock@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <clock_gettime@plt>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xdc8(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x60(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    128a <main+0x10a>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a3 <main+0x123>
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   10b0 <pthread_mutex_lock@plt>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dff(%rip),%r13
mov    0x0(%r13),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe14(%rip),%r12
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1080 <strftime@plt>
lea    0xdf8(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
addl   $0xa,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <pthread_mutex_timedlock@plt>
mov    %eax,%ebp
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %r15,%rdi
mov    $0x40,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1080 <strftime@plt>
lea    0xdc2(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
jne    1283 <main+0xf3>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xda7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@.str = [13 x i8] c"hello world!\00"
@PTHREAD_MUTEX_INITIALIZER = global i32 0
@.str.1 = [17 x i8] c"mutex is locked\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [3 x i8] c"%r\00"
@.str.3 = [20 x i8] c"current time is %s\0A\00"
@.str.4 = [20 x i8] c"the time is now %s\0A\00"
@.str.5 = [21 x i8] c"mutex locked again!\0A\00"
@.str.6 = [30 x i8] c"can't locked mutex again: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.tm*
%5 = alloca [64 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %8, i32* %6
%9 = call i32 @pthread_mutex_lock(i32* %6)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %3)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%14 = call %struct.tm* @localtime(i32* %13)
store %struct.tm* %14, %struct.tm** %4
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%16 = load %struct.tm*, %struct.tm** %4
%17 = call i32 @strftime(i8* %15, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 10
store i32 %22, i32* %20
%23 = call i32 @pthread_mutex_timedlock(i32* %6, %struct.timespec* %3)
store i32 %23, i32* %2
%24 = load i32, i32* @CLOCK_REALTIME
%25 = call i32 @clock_gettime(i32 %24, %struct.timespec* %3)
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%27 = call %struct.tm* @localtime(i32* %26)
store %struct.tm* %27, %struct.tm** %4
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%29 = load %struct.tm*, %struct.tm** %4
%30 = call i32 @strftime(i8* %28, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %2
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %41
37: ; preds = %0
%38 = load i32, i32* %2
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %37, %35
%42 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@.str = [13 x i8] c"hello world!\00"
@PTHREAD_MUTEX_INITIALIZER = global i32 0
@CLOCK_REALTIME = global i32 0
@.str.2 = [3 x i8] c"%r\00"
@.str.3 = [20 x i8] c"current time is %s\0A\00"
@.str.4 = [20 x i8] c"the time is now %s\0A\00"
@.str.6 = [30 x i8] c"can't locked mutex again: %s\0A\00"
@str = [16 x i8] c"mutex is locked\00"
@str.7 = [20 x i8] c"mutex locked again!\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = bitcast %struct.timespec* %1 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %8, i32* %3
%9 = call i32 @pthread_mutex_lock(i32* %3)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %1)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%14 = call %struct.tm* @localtime(i32* %13)
%15 = call i32 @strftime(i8* %6, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%17 = load i32, i32* %13
%18 = add nsw i32 %17, 10
store i32 %18, i32* %13
%19 = call i32 @pthread_mutex_timedlock(i32* %3, %struct.timespec* %1)
%20 = load i32, i32* @CLOCK_REALTIME
%21 = call i32 @clock_gettime(i32 %20, %struct.timespec* %1)
%22 = call %struct.tm* @localtime(i32* %13)
%23 = call i32 @strftime(i8* %6, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%25 = icmp eq i32 %19, 0
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
br label %31
28: ; preds = %0
%29 = call i8* @strerror(i32 %19)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %26
%32 = call i32 @exit(i32 0)
unreachable
}