#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int setenv(char *, char *, int);
int set_delta(time_t delta) {
  int retv = setenv("LIBTIMEMACHINE_CONF", "test_timemachine.conf", 1);
  if (retv != 0) {
    return -1;
  }
  FILE *file = fopen("test_timemachine.conf", "w");
  if (file == NULL) {
    return -2;
  }
  fprintf(file, "%d", (int)delta);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<set_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeba(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117d <set_delta+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <set_delta+0x91>
lea    0xe90(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <set_delta+0x6b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d1 <set_delta+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_delta>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xebf(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    11a8 <set_delta+0x68>
lea    0xea3(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <set_delta+0x63>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11a8 <set_delta+0x68>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"LIBTIMEMACHINE_CONF\00"
@.str.1 = [22 x i8] c"test_timemachine.conf\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @set_delta(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32*
store i64 %0, i64* %3
%6 = call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %22
10: ; preds = %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -2, i32* %2
br label %22
15: ; preds = %10
%16 = load i32*, i32** %5
%17 = load i64, i64* %3
%18 = trunc i64 %17 to i32
%19 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %2
br label %22
22: ; preds = %15, %14, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [20 x i8] c"LIBTIMEMACHINE_CONF\00"
@.str.1 = [22 x i8] c"test_timemachine.conf\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @set_delta(i64 %0) {
%2 = tail call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = trunc i64 %0 to i32
%9 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @fclose(i32* %5)
br label %11
11: ; preds = %7, %4, %1
%12 = phi i32 [ -1, %1 ], [ 0, %7 ], [ -2, %4 ]
ret i32 %12
}