#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 timezone {
  int dummy;
};
struct timeval {
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ printf(char *, int);
int random();
int /*<<< orphan*/ srandom(int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int last;
  if (argc != 2) {
  error:
    fprintf(stderr, "*** rand last_number\n");
    exit(20);
  }
  if (sscanf(argv[1], "%d", &last) != 1)
    goto error;
  if (last)
    srandom(last);
  else {
    struct timeval t;
    struct timezone tz;
    gettimeofday(&t, &tz);
    srandom(t.tv_sec);
  }
  printf("%d\n", random());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b4 <main+0x44>
jmp    1195 <main+0x25>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x14,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe53(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11da <main+0x6a>
jmp    1195 <main+0x25>
cmpl   $0x0,-0x14(%rbp)
je     11f1 <main+0x81>
mov    -0x14(%rbp),%edi
call   1030 <srandom@plt>
jmp    1206 <main+0x96>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
call   1030 <srandom@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11cf <main+0x5f>
mov    0x8(%rsi),%rdi
lea    0xe92(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11cf <main+0x5f>
mov    0xc(%rsp),%edi
test   %edi,%edi
jne    11ae <main+0x3e>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%edi
call   1030 <srandom@plt>
xor    %eax,%eax
call   1070 <random@plt>
lea    0xe58(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x14,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"*** rand last_number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.timezone
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
br label %12
12: ; preds = %22, %11
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 20)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %16
br label %12
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call i32 @srandom(i32 %27)
br label %34
29: ; preds = %23
%30 = call i32 @gettimeofday(%struct.timeval* %7, %struct.timezone* %8)
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @srandom(i32 %32)
br label %34
34: ; preds = %29, %26
%35 = call i32 (...) @random()
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"*** rand last_number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.timezone
%6 = bitcast i32* %3 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %12, %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 20)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %8
17: ; preds = %12
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @srandom(i32 %18)
br label %29
22: ; preds = %17
%23 = bitcast %struct.timeval* %4 to i8*
%24 = bitcast %struct.timezone* %5 to i8*
%25 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @srandom(i32 %27)
br label %29
29: ; preds = %22, %20
%30 = call i32 (...) @random()
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
ret i32 0
}