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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
long atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  while (1) {
    int fd = -1, ret;
    char *tmp1, tmp2[10], ch = 't';
    char devname_head[50] = "/sys/devices/w1_bus_master1/28-";
    char devname_end[10] = "/w1_slave";
    char dev_name[100];
    long value;
    int integer, decimal;
    char buffer[100];
    int i, j;
    strcpy(dev_name, devname_head);
    strcat(dev_name, argv[1]);
    strcat(dev_name, devname_end);
    if ((fd = open(dev_name, O_RDONLY)) < 0) {
      perror("open error");
      exit(1);
    }
    ret = read(fd, buffer, sizeof(buffer));
    if (ret < 0) {
      perror("read error");
      exit(1);
    }
    tmp1 = strchr(buffer, ch);
    sscanf(tmp1, "t=%s", tmp2);
    value = atoi(tmp2);
    integer = value / 1000;
    decimal = value % 1000;
    printf("temperature is %d.%d\n", integer, decimal);
    close(fd);
    FILE *fp;
    if ((fp = fopen("tmdata", "w")) == NULL) {
      printf("Cannot open file\n");
      exit(0);
    }
    fprintf(fp, "%d.%d 0", integer, decimal);
    fclose(fp);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movb   $0x74,-0x2b(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xdd1(%rip),%rsi
mov    $0x32,%edx
call   10a0 <memcpy@plt>
mov    0xdf2(%rip),%rax
mov    %rax,-0x6a(%rbp)
mov    0xdef(%rip),%ax
mov    %ax,-0x62(%rbp)
lea    -0xd0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1100 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x6a(%rbp),%rsi
call   1100 <strcat@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12ba <main+0xba>
lea    0xd91(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12f1 <main+0xf1>
lea    0xd65(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x150(%rbp),%rdi
movsbl -0x2b(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x2a(%rbp),%rdx
lea    0xd3e(%rip),%rsi
call   10b0 <sscanf@plt>
lea    -0x2a(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %eax,-0xdc(%rbp)
mov    -0xd8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0xe0(%rbp)
mov    -0xdc(%rbp),%esi
mov    -0xe0(%rbp),%edx
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
lea    0xceb(%rip),%rdi
lea    0xceb(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x160(%rbp)
cmp    $0x0,%rax
jne    13b4 <main+0x1b4>
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x160(%rbp),%rdi
mov    -0xdc(%rbp),%edx
mov    -0xe0(%rbp),%ecx
lea    0xcba(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x160(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
jmp    1219 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,0x18(%rsp)
lea    0xd0(%rsp),%r13
lea    0x60(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movaps 0xde9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdcd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xdb1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movw   $0x0,0x50(%rsp)
movabs $0x76616c735f31772f,%rax
6c 61 76
mov    %rax,0x8(%rsp)
movw   $0x65,0x10(%rsp)
mov    %r13,%rdi
lea    0x20(%rsp),%rsi
call   1030 <strcpy@plt>
mov    0x18(%rsp),%rax
mov    0x8(%rax),%rsi
mov    %r13,%rdi
call   1100 <strcat@plt>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   1100 <strcat@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     138c <main+0x18c>
mov    %eax,%r12d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1090 <read@plt>
test   %eax,%eax
js     1395 <main+0x195>
mov    %rbx,%r15
mov    %rbx,%rdi
mov    $0x74,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
lea    0xd69(%rip),%rsi
lea    0x56(%rsp),%rbx
mov    %rbx,%rdx
call   10b0 <sscanf@plt>
mov    %rbx,%rdi
call   10f0 <atoi@plt>
mov    %rax,%rbp
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
imul   %rcx
mov    %rdx,%r14
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x7,%r14
add    %eax,%r14d
imul   $0x3e8,%r14d,%eax
sub    %eax,%ebp
lea    0xd28(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
lea    0xd23(%rip),%rdi
lea    0xd23(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13ab <main+0x1ab>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xd0e(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    %r15,%rbx
jmp    1230 <main+0x30>
lea    0xca9(%rip),%rdi
jmp    139c <main+0x19c>
lea    0xcab(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xccc(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@__const.main.devname_head = [50 x i8] c"/sys/devices/w1_bus_master1/28-\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.devname_end = [10 x i8] c"/w1_slave\00"
@O_RDONLY = global i32 0
@.str = [11 x i8] c"open error\00"
@.str.1 = [11 x i8] c"read error\00"
@.str.2 = [5 x i8] c"t=%s\00"
@.str.3 = [22 x i8] c"temperature is %d.%d\0A\00"
@.str.4 = [7 x i8] c"tmdata\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [18 x i8] c"Cannot open file\0A\00"
@.str.7 = [8 x i8] c"%d.%d 0\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [10 x i8]
%10 = alloca i8
%11 = alloca [50 x i8]
%12 = alloca [10 x i8]
%13 = alloca [100 x i8]
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca [100 x i8]
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %21
21: ; preds = %2, %76
store i32 -1, i32* %6
store i8 116, i8* %10
%22 = bitcast [50 x i8]* %11 to i8*
%23 = bitcast [10 x i8]* %12 to i8*
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcat(i8* %27, i8* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %21
%40 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %21
%43 = load i32, i32* %6
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 100)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i64 0, i64 0
%53 = load i8, i8* %10
%54 = call i8* @strchr(i8* %52, i8 signext %53)
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%57 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%59 = call i64 @atoi(i8* %58)
store i64 %59, i64* %14
%60 = load i64, i64* %14
%61 = sdiv i64 %60, 1000
%62 = trunc i64 %61 to i32
store i32 %62, i32* %15
%63 = load i64, i64* %14
%64 = srem i64 %63, 1000
%65 = trunc i64 %64 to i32
store i32 %65, i32* %16
%66 = load i32, i32* %15
%67 = load i32, i32* %16
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %66, i32 %67)
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
%71 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %71, i32** %20
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %76
73: ; preds = %51
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
76: ; preds = %51
%77 = load i32*, i32** %20
%78 = load i32, i32* %15
%79 = load i32, i32* %16
%80 = call i32 @fprintf(i32* %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %78, i32 %79)
%81 = load i32*, i32** %20
%82 = call i32 @fclose(i32* %81)
%83 = call i32 @sleep(i32 1)
br label %21
}

LLVM IR (-O2):
@__const.main.devname_head = [50 x i8] c"/sys/devices/w1_bus_master1/28-\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.devname_end = [10 x i8] c"/w1_slave\00"
@O_RDONLY = global i32 0
@.str = [11 x i8] c"open error\00"
@.str.1 = [11 x i8] c"read error\00"
@.str.2 = [5 x i8] c"t=%s\00"
@.str.3 = [22 x i8] c"temperature is %d.%d\0A\00"
@.str.4 = [7 x i8] c"tmdata\00"
@.str.5 = [2 x i8] c"w\00"
@.str.7 = [8 x i8] c"%d.%d 0\00"
@str = [17 x i8] c"Cannot open file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca [50 x i8]
%5 = alloca [10 x i8]
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds i8*, i8** %1, i64 1
br label %14
14: ; preds = %2, %46
%15 = call i32 @strcpy(i8* %11, i8* %9)
%16 = load i8*, i8** %13
%17 = call i32 @strcat(i8* %11, i8* %16)
%18 = call i32 @strcat(i8* %11, i8* %10)
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %11, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %14
%26 = call i32 @read(i32 %20, i8* %12, i32 100)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = call i8* @strchr(i8* %12, i8 signext 116)
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%34 = call i64 @atoi(i8* %8)
%35 = sdiv i64 %34, 1000
%36 = trunc i64 %35 to i32
%37 = srem i64 %34, 1000
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %38)
%40 = call i32 @close(i32 %20)
%41 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %31
%47 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %36, i32 %38)
%48 = call i32 @fclose(i32* %41)
%49 = call i32 @sleep(i32 1)
br label %14
}