#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 scalar_t__ time_t;
typedef scalar_t__ suseconds_t;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct timespec {
  long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ atol(char *);
scalar_t__ atoll(char *);
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int clock_settime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int gettimeofday_syscall(struct timeval *);
int /*<<< orphan*/ perror(char *);
int settimeofday_syscall(struct timeval *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int main(int argc, char **argv) {
  const char *mode;
  struct timespec ts, ts_orig;
  struct timeval tv, tv_orig;
  int ret;
  if (argc != 4) {
    fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
    return 1;
  }
  mode = argv[1];
  tv.tv_sec = (time_t)atoll(argv[2]);
  tv.tv_usec = (suseconds_t)atol(argv[3]);
  ts.tv_sec = tv.tv_sec;
  ts.tv_nsec = (long)tv.tv_usec * 1000;
  if (strcmp(mode, "posix") == 0) {
    ret = clock_gettime(CLOCK_REALTIME, &ts_orig);
    if (ret) {
      perror("clock_gettime");
      return 1;
    }
    ret = clock_settime(CLOCK_REALTIME, &ts);
    if (ret) {
      perror("clock_settime (set)");
      return 1;
    }
    ret = clock_settime(CLOCK_REALTIME, &ts_orig);
    if (ret) {
      perror("clock_settime (reset)");
      return 1;
    }
  } else if (strcmp(mode, "settimeofday") == 0) {
    ret = gettimeofday_syscall(&tv_orig);
    if (ret) {
      perror("gettimeofday");
      return 1;
    }
    ret = settimeofday_syscall(&tv);
    if (ret) {
      perror("settimeofday (set)");
      return 1;
    }
    ret = settimeofday_syscall(&tv_orig);
    if (ret) {
      perror("settimeofday (reset)");
      return 1;
    }
  } else {
    fprintf(stderr, "%s: invalid mode: %s\n", argv[0], mode);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoll@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atol@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0x3e8,-0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12e0 <main+0x150>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     126d <main+0xdd>
lea    0xdc9(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1090 <clock_settime@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     12a4 <main+0x114>
lea    0xda0(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1090 <clock_settime@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     12db <main+0x14b>
lea    0xd7d(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
jmp    13bc <main+0x22c>
mov    -0x18(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1389 <main+0x1f9>
lea    -0x58(%rbp),%rdi
call   1080 <gettimeofday_syscall@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1328 <main+0x198>
lea    0xd53(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
lea    -0x48(%rbp),%rdi
call   1040 <settimeofday_syscall@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1356 <main+0x1c6>
lea    0xd32(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
lea    -0x58(%rbp),%rdi
call   1040 <settimeofday_syscall@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1384 <main+0x1f4>
lea    0xd17(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
jmp    13b7 <main+0x227>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x233>
jmp    13bc <main+0x22c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r15
cmp    $0x4,%edi
jne    1220 <main+0x90>
mov    0x8(%r15),%r14
mov    0x10(%r15),%rdi
call   1050 <atoll@plt>
mov    %rax,%rbx
mov    %rax,0x18(%rsp)
mov    0x18(%r15),%rdi
call   10a0 <atol@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,0x28(%rsp)
imul   $0x3e8,%rax,%rax
mov    %rax,0x20(%rsp)
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1249 <main+0xb9>
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     128e <main+0xfe>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe8b(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    123a <main+0xaa>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d88(%rip),%rbx
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
test   %eax,%eax
jne    12c9 <main+0x139>
mov    (%rbx),%edi
lea    0x20(%rsp),%rsi
call   1090 <clock_settime@plt>
test   %eax,%eax
jne    12da <main+0x14a>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1090 <clock_settime@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     123f <main+0xaf>
lea    0xdc0(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>
mov    %rsp,%rdi
call   1080 <gettimeofday_syscall@plt>
test   %eax,%eax
jne    12eb <main+0x15b>
lea    0x10(%rsp),%rdi
call   1040 <settimeofday_syscall@plt>
test   %eax,%eax
jne    12fc <main+0x16c>
mov    %rsp,%rdi
call   1040 <settimeofday_syscall@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     123f <main+0xaf>
lea    0xdcb(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>
lea    0xd55(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>
lea    0xd52(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>
lea    0xd78(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>
lea    0xd74(%rip),%rdi
call   10b0 <perror@plt>
jmp    123a <main+0xaa>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [31 x i8] c"%s: wrong number of arguments\0A\00"
@.str.1 = [6 x i8] c"posix\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [14 x i8] c"clock_gettime\00"
@.str.3 = [20 x i8] c"clock_settime (set)\00"
@.str.4 = [22 x i8] c"clock_settime (reset)\00"
@.str.5 = [13 x i8] c"settimeofday\00"
@.str.6 = [13 x i8] c"gettimeofday\00"
@.str.7 = [19 x i8] c"settimeofday (set)\00"
@.str.8 = [21 x i8] c"settimeofday (reset)\00"
@.str.9 = [22 x i8] c"%s: invalid mode: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %98
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @atoll(i8* %26)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i64 %27, i64* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i64 @atol(i8* %31)
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i64 %32, i64* %33
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 %35, i64* %36
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%38 = load i64, i64* %37
%39 = mul nsw i64 %38, 1000
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store i64 %39, i64* %40
%41 = load i8*, i8** %6
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %66
44: ; preds = %20
%45 = load i32, i32* @CLOCK_REALTIME
%46 = call i32 @clock_gettime(i32 %45, %struct.timespec* %8)
store i32 %46, i32* %11
%47 = load i32, i32* %11
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %98
51: ; preds = %44
%52 = load i32, i32* @CLOCK_REALTIME
%53 = call i32 @clock_settime(i32 %52, %struct.timespec* %7)
store i32 %53, i32* %11
%54 = load i32, i32* %11
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %98
58: ; preds = %51
%59 = load i32, i32* @CLOCK_REALTIME
%60 = call i32 @clock_settime(i32 %59, %struct.timespec* %8)
store i32 %60, i32* %11
%61 = load i32, i32* %11
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %58
%64 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %98
65: ; preds = %58
br label %97
66: ; preds = %20
%67 = load i8*, i8** %6
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %89
70: ; preds = %66
%71 = call i32 @gettimeofday_syscall(%struct.timeval* %10)
store i32 %71, i32* %11
%72 = load i32, i32* %11
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %98
76: ; preds = %70
%77 = call i32 @settimeofday_syscall(%struct.timeval* %9)
store i32 %77, i32* %11
%78 = load i32, i32* %11
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %98
82: ; preds = %76
%83 = call i32 @settimeofday_syscall(%struct.timeval* %10)
store i32 %83, i32* %11
%84 = load i32, i32* %11
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %98
88: ; preds = %82
br label %96
89: ; preds = %66
%90 = load i32, i32* @stderr
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 0
%93 = load i8*, i8** %92
%94 = load i8*, i8** %6
%95 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %93, i8* %94)
store i32 1, i32* %3
br label %98
96: ; preds = %88
br label %97
97: ; preds = %96, %65
store i32 0, i32* %3
br label %98
98: ; preds = %97, %89, %86, %80, %74, %63, %56, %49, %14
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [31 x i8] c"%s: wrong number of arguments\0A\00"
@.str.1 = [6 x i8] c"posix\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [14 x i8] c"clock_gettime\00"
@.str.3 = [20 x i8] c"clock_settime (set)\00"
@.str.4 = [22 x i8] c"clock_settime (reset)\00"
@.str.5 = [13 x i8] c"settimeofday\00"
@.str.6 = [13 x i8] c"gettimeofday\00"
@.str.7 = [19 x i8] c"settimeofday (set)\00"
@.str.8 = [21 x i8] c"settimeofday (reset)\00"
@.str.9 = [22 x i8] c"%s: invalid mode: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = bitcast %struct.timespec* %3 to i8*
%8 = bitcast %struct.timespec* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = icmp eq i32 %0, 4
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %72
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i64 @atoll(i8* %20)
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 %21, i64* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i64 @atol(i8* %24)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i64 %25, i64* %26
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 %21, i64* %27
%28 = mul nsw i64 %25, 1000
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i64 %28, i64* %29
%30 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %50
32: ; preds = %16
%33 = load i32, i32* @CLOCK_REALTIME
%34 = call i32 @clock_gettime(i32 %33, %struct.timespec* %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %72
38: ; preds = %32
%39 = load i32, i32* @CLOCK_REALTIME
%40 = call i32 @clock_settime(i32 %39, %struct.timespec* %3)
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %72
44: ; preds = %38
%45 = load i32, i32* @CLOCK_REALTIME
%46 = call i32 @clock_settime(i32 %45, %struct.timespec* %4)
%47 = icmp eq i32 %46, 0
br i1 %47, label %72, label %48
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %72
50: ; preds = %16
%51 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %68
53: ; preds = %50
%54 = call i32 @gettimeofday_syscall(%struct.timeval* %6)
%55 = icmp eq i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %72
58: ; preds = %53
%59 = call i32 @settimeofday_syscall(%struct.timeval* %5)
%60 = icmp eq i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %72
63: ; preds = %58
%64 = call i32 @settimeofday_syscall(%struct.timeval* %6)
%65 = icmp eq i32 %64, 0
br i1 %65, label %72, label %66
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %72
68: ; preds = %50
%69 = load i32, i32* @stderr
%70 = load i8*, i8** %1
%71 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %70, i8* %18)
br label %72
72: ; preds = %44, %63, %68, %66, %61, %56, %48, %42, %36, %12
%73 = phi i32 [ 1, %12 ], [ 1, %36 ], [ 1, %42 ], [ 1, %48 ], [ 1, %56 ], [ 1, %61 ], [ 1, %66 ], [ 1, %68 ], [ 0, %63 ], [ 0, %44 ]
ret i32 %73
}