#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 EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ LC_ALL;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int put_infos(char *);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  char *format = "%a %H:%M";
  int interval = 3;
  bool snoop = false;
  int opt;
  while ((opt = getopt(argc, argv, "hsf:i:")) != -1) {
    switch (opt) {
    case 'h':
      printf("clock [-h|-s|-f FORMAT|-i INTERVAL]\n");
      exit(EXIT_SUCCESS);
      break;
    case 's':
      snoop = true;
      break;
    case 'f':
      format = optarg;
      break;
    case 'i':
      interval = atoi(optarg);
      break;
    }
  }
  int exit_code;
  if (setlocale(LC_ALL, "") == NULL)
    perror("setlocale");
  if (snoop)
    while ((exit_code = put_infos(format)) != EXIT_FAILURE)
      sleep(interval);
  else
    exit_code = put_infos(format);
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1247 <main+0xc7>
mov    -0x24(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xd,%eax
ja     1242 <main+0xc2>
mov    -0x30(%rbp),%rax
lea    0xe12(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x1,-0x20(%rbp)
jmp    1242 <main+0xc2>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1242 <main+0xc2>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11af <main+0x2f>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%rax
jne    1272 <main+0xf2>
lea    0xe00(%rip),%rdi
call   1060 <perror@plt>
cmpl   $0x0,-0x20(%rbp)
je     12ae <main+0x12e>
jmp    1281 <main+0x101>
mov    -0x18(%rbp),%rdi
call   1040 <put_infos@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d44(%rip),%rcx
cmp    (%rcx),%eax
je     12a9 <main+0x129>
mov    -0x1c(%rbp),%edi
call   10a0 <sleep@plt>
jmp    1281 <main+0x101>
jmp    12ba <main+0x13a>
mov    -0x18(%rbp),%rdi
call   1040 <put_infos@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea1(%rip),%r14
movl   $0x0,0x4(%rsp)
mov    $0x3,%r15d
lea    0xe95(%rip),%r12
lea    0xe4d(%rip),%r13
jmp    11c5 <main+0x45>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xffffffff,%eax
je     120e <main+0x8e>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
lea    -0x66(%rax),%ecx
cmp    $0xd,%ecx
ja     11c0 <main+0x40>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x2e0d(%rip),%rax
mov    (%rax),%r14
jmp    11c5 <main+0x45>
mov    0x2e01(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
jmp    11c5 <main+0x45>
movl   $0x1,0x4(%rsp)
jmp    11c5 <main+0x45>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <setlocale@plt>
test   %rax,%rax
je     1273 <main+0xf3>
mov    %r14,%rdi
call   1040 <put_infos@plt>
cmpl   $0x0,0x4(%rsp)
je     1264 <main+0xe4>
mov    0x2d9a(%rip),%rbx
cmp    (%rbx),%eax
je     1264 <main+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
call   1040 <put_infos@plt>
cmp    (%rbx),%eax
jne    1250 <main+0xd0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdce(%rip),%rdi
call   1060 <perror@plt>
jmp    1228 <main+0xa8>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%a %H:%M\00"
@.str.1 = [7 x i8] c"hsf:i:\00"
@.str.2 = [37 x i8] c"clock [-h|-s|-f FORMAT|-i INTERVAL]\0A\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@LC_ALL = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [10 x i8] c"setlocale\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 3, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %28 [
i32 104, label %18
i32 115, label %22
i32 102, label %23
i32 105, label %25
]
18: ; preds = %16
%19 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
store i32 1, i32* %8
br label %28
23: ; preds = %16
%24 = load i8*, i8** @optarg
store i8* %24, i8** %6
br label %28
25: ; preds = %16
%26 = load i8*, i8** @optarg
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
br label %28
28: ; preds = %16, %25, %23, %22
br label %11
29: ; preds = %11
%30 = load i32, i32* @LC_ALL
%31 = call i32* @setlocale(i32 %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %35
br label %39
39: ; preds = %44, %38
%40 = load i8*, i8** %6
%41 = call i32 @put_infos(i8* %40)
store i32 %41, i32* %10
%42 = load i32, i32* @EXIT_FAILURE
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* %7
%46 = call i32 @sleep(i32 %45)
br label %39
47: ; preds = %39
br label %51
48: ; preds = %35
%49 = load i8*, i8** %6
%50 = call i32 @put_infos(i8* %49)
store i32 %50, i32* %10
br label %51
51: ; preds = %48, %47
%52 = load i32, i32* %10
ret i32 %52
}

LLVM IR (-O2):
@.str = [9 x i8] c"%a %H:%M\00"
@.str.1 = [7 x i8] c"hsf:i:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@LC_ALL = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [10 x i8] c"setlocale\00"
@EXIT_FAILURE = global i32 0
@str = [36 x i8] c"clock [-h|-s|-f FORMAT|-i INTERVAL]\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %20, %2
%4 = phi i32 [ %22, %20 ], [ 3, %2 ]
%5 = phi i32 [ %8, %20 ], [ 0, %2 ]
%6 = phi i8* [ %11, %20 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %12, %3
%8 = phi i32 [ %5, %3 ], [ 1, %12 ]
%9 = phi i8* [ %6, %3 ], [ %11, %12 ]
br label %10
10: ; preds = %7, %18
%11 = phi i8* [ %9, %7 ], [ %19, %18 ]
br label %12
12: ; preds = %10, %12
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
switch i32 %13, label %12 [
i32 -1, label %23
i32 104, label %14
i32 115, label %7
i32 102, label %18
i32 105, label %20
]
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_SUCCESS
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %12
%19 = load i8*, i8** @optarg
br label %10
20: ; preds = %12
%21 = load i8*, i8** @optarg
%22 = tail call i32 @atoi(i8* %21)
br label %3
23: ; preds = %12
%24 = load i32, i32* @LC_ALL
%25 = tail call i32* @setlocale(i32 %24, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = icmp eq i32 %8, 0
%31 = tail call i32 @put_infos(i8* %11)
%32 = load i32, i32* @EXIT_FAILURE
%33 = icmp eq i32 %31, %32
%34 = select i1 %30, i1 true, i1 %33
br i1 %34, label %40, label %35
35: ; preds = %29, %35
%36 = tail call i32 @sleep(i32 %4)
%37 = tail call i32 @put_infos(i8* %11)
%38 = load i32, i32* @EXIT_FAILURE
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %35
40: ; preds = %35, %29
%41 = phi i32 [ %31, %29 ], [ %37, %35 ]
ret i32 %41
}