#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 edid_info {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ DDC_Deinit();
int /*<<< orphan*/ DDC_Init(char *);
int DDC_Probe();
struct edid_info *DDC_ProbeEdid();
int atoi(char *);
int /*<<< orphan*/ dump_edidinfo(struct edid_info *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  struct edid_info *pinfo = NULL;
  int interval = 0;
  int ret = 0;
  if (argc == 1) {
    DDC_Init("/dev/i2c-2");
    pinfo = DDC_ProbeEdid();
    if (pinfo) {
      printf("get pinfo ok\n");
      dump_edidinfo(pinfo);
    } else {
      printf("probe nothing ... \n");
    }
    DDC_Deinit();
    return 0;
  } else if (argc == 2) {
    interval = atoi(argv[1]);
    DDC_Init("/dev/i2c-2");
    while (1) {
      ret = DDC_Probe();
      if (ret) {
        printf("probe nothing (%d) ... \n", ret);
        sleep(interval);
        continue;
      }
      pinfo = DDC_ProbeEdid();
      if (pinfo) {
        dump_edidinfo(pinfo);
      } else {
        printf("probe edid failed ... \n");
      }
      break;
    }
    DDC_Deinit();
    return 0;
  } else
    print_usage();
  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)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1225 <main+0x95>
lea    0xe33(%rip),%rdi
call   1040 <DDC_Init@plt>
mov    $0x0,%al
call   10a0 <DDC_ProbeEdid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1204 <main+0x74>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <dump_edidinfo@plt>
jmp    1212 <main+0x82>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <DDC_Deinit@plt>
movl   $0x0,-0x4(%rbp)
jmp    12da <main+0x14a>
cmpl   $0x2,-0x8(%rbp)
jne    12c7 <main+0x137>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdba(%rip),%rdi
call   1040 <DDC_Init@plt>
mov    $0x0,%al
call   1030 <DDC_Probe@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     127d <main+0xed>
mov    -0x20(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <sleep@plt>
jmp    124b <main+0xbb>
mov    $0x0,%al
call   10a0 <DDC_ProbeEdid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12a1 <main+0x111>
mov    -0x18(%rbp),%rdi
call   1090 <dump_edidinfo@plt>
jmp    12af <main+0x11f>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b4 <main+0x124>
mov    $0x0,%al
call   1060 <DDC_Deinit@plt>
movl   $0x0,-0x4(%rbp)
jmp    12da <main+0x14a>
mov    $0x0,%al
call   1080 <print_usage@plt>
jmp    12d3 <main+0x143>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
je     11ea <main+0x4a>
cmp    $0x1,%edi
jne    1254 <main+0xb4>
lea    0xe47(%rip),%rdi
call   1050 <DDC_Init@plt>
xor    %eax,%eax
call   10b0 <DDC_ProbeEdid@plt>
test   %rax,%rax
je     125d <main+0xbd>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   10a0 <dump_edidinfo@plt>
jmp    1272 <main+0xd2>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xe04(%rip),%rdi
call   1050 <DDC_Init@plt>
xor    %eax,%eax
call   1040 <DDC_Probe@plt>
test   %eax,%eax
je     123e <main+0x9e>
lea    0xdf8(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
call   1040 <DDC_Probe@plt>
test   %eax,%eax
jne    1220 <main+0x80>
xor    %eax,%eax
call   10b0 <DDC_ProbeEdid@plt>
test   %rax,%rax
je     1266 <main+0xc6>
mov    %rax,%rdi
call   10a0 <dump_edidinfo@plt>
jmp    1272 <main+0xd2>
xor    %eax,%eax
call   1090 <print_usage@plt>
jmp    1279 <main+0xd9>
lea    0xdd7(%rip),%rdi
jmp    126d <main+0xcd>
lea    0xdb7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <DDC_Deinit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.edid_info = type { i32 }
@.str = [11 x i8] c"/dev/i2c-2\00"
@.str.1 = [14 x i8] c"get pinfo ok\0A\00"
@.str.2 = [20 x i8] c"probe nothing ... \0A\00"
@.str.3 = [25 x i8] c"probe nothing (%d) ... \0A\00"
@.str.4 = [24 x i8] c"probe edid failed ... \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.edid_info*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.edid_info* null, %struct.edid_info** %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = call i32 @DDC_Init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = call %struct.edid_info* (...) @DDC_ProbeEdid()
store %struct.edid_info* %13, %struct.edid_info** %6
%14 = load %struct.edid_info*, %struct.edid_info** %6
%15 = icmp ne %struct.edid_info* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = load %struct.edid_info*, %struct.edid_info** %6
%19 = call i32 @dump_edidinfo(%struct.edid_info* %18)
br label %22
20: ; preds = %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = call i32 (...) @DDC_Deinit()
store i32 0, i32* %3
br label %58
24: ; preds = %2
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %54
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %7
%32 = call i32 @DDC_Init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %27, %37
%34 = call i32 (...) @DDC_Probe()
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %7
%41 = call i32 @sleep(i32 %40)
br label %33
42: ; preds = %33
%43 = call %struct.edid_info* (...) @DDC_ProbeEdid()
store %struct.edid_info* %43, %struct.edid_info** %6
%44 = load %struct.edid_info*, %struct.edid_info** %6
%45 = icmp ne %struct.edid_info* %44, null
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load %struct.edid_info*, %struct.edid_info** %6
%48 = call i32 @dump_edidinfo(%struct.edid_info* %47)
br label %51
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
br label %52
52: ; preds = %51
%53 = call i32 (...) @DDC_Deinit()
store i32 0, i32* %3
br label %58
54: ; preds = %24
%55 = call i32 (...) @print_usage()
br label %56
56: ; preds = %54
br label %57
57: ; preds = %56
store i32 0, i32* %3
br label %58
58: ; preds = %57, %52, %22
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.edid_info = type { i32 }
@.str = [11 x i8] c"/dev/i2c-2\00"
@.str.3 = [25 x i8] c"probe nothing (%d) ... \0A\00"
@str = [23 x i8] c"probe edid failed ... \00"
@str.5 = [19 x i8] c"probe nothing ... \00"
@str.6 = [13 x i8] c"get pinfo ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %36 [
i32 1, label %3
i32 2, label %14
]
3: ; preds = %2
%4 = tail call i32 @DDC_Init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = tail call %struct.edid_info* (...) @DDC_ProbeEdid()
%6 = icmp eq %struct.edid_info* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @dump_edidinfo(%struct.edid_info* %5)
br label %12
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 (...) @DDC_Deinit()
br label %38
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @DDC_Init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 (...) @DDC_Probe()
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %14, %21
%22 = phi i32 [ %25, %21 ], [ %19, %14 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = tail call i32 @sleep(i32 %17)
%25 = tail call i32 (...) @DDC_Probe()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %21
27: ; preds = %21, %14
%28 = tail call %struct.edid_info* (...) @DDC_ProbeEdid()
%29 = icmp eq %struct.edid_info* %28, null
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @dump_edidinfo(%struct.edid_info* %28)
br label %34
32: ; preds = %27
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %30, %32
%35 = tail call i32 (...) @DDC_Deinit()
br label %38
36: ; preds = %2
%37 = tail call i32 (...) @print_usage()
br label %38
38: ; preds = %36, %34, %12
ret i32 0
}